Skip to content

Commit

Permalink
Breaking: lifecycleExperimental as the default option
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 committed Sep 23, 2017
1 parent f62b6c0 commit e8296d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
32 changes: 13 additions & 19 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3185,7 +3185,6 @@ describe('shallow', () => {
<Foo foo="bar" />,
{
context: { foo: 'context' },
lifecycleExperimental: true,
},
);
wrapper.setProps({ foo: 'baz' });
Expand Down Expand Up @@ -3275,7 +3274,7 @@ describe('shallow', () => {
}
}

const wrapper = shallow(<Foo a="a" b="b" />, { lifecycleExperimental: true });
const wrapper = shallow(<Foo a="a" b="b" />);

wrapper.setProps({ b: 'c', d: 'e' });

Expand Down Expand Up @@ -3326,7 +3325,7 @@ describe('shallow', () => {
}
}

const wrapper = shallow(<Foo foo="bar" />, { lifecycleExperimental: true });
const wrapper = shallow(<Foo foo="bar" />);
expect(wrapper.instance().props.foo).to.equal('bar');
wrapper.setProps({ foo: 'baz' });
expect(wrapper.instance().props.foo).to.equal('baz');
Expand Down Expand Up @@ -3359,7 +3358,7 @@ describe('shallow', () => {
return <div>{this.props.foo}</div>;
}
}
const result = shallow(<Foo />, { lifecycleExperimental: true });
const result = shallow(<Foo />);
expect(spy).to.have.property('callCount', 1);
result.setProps({ name: 'bar' });
expect(spy).to.have.property('callCount', 2);
Expand Down Expand Up @@ -3388,7 +3387,7 @@ describe('shallow', () => {
return <div>{this.props.foo}</div>;
}
}
const result = shallow(<Foo />, { lifecycleExperimental: true });
const result = shallow(<Foo />);
expect(spy).to.have.property('callCount', 1);
result.setProps({ name: 'bar' });
expect(spy).to.have.property('callCount', 3);
Expand Down Expand Up @@ -3419,7 +3418,7 @@ describe('shallow', () => {
return <div>{this.props.foo}</div>;
}
}
const result = shallow(<Foo />, { lifecycleExperimental: true });
const result = shallow(<Foo />);
expect(spy).to.have.property('callCount', 1);
result.setProps({ name: 'bar' });
expect(spy).to.have.property('callCount', 3);
Expand Down Expand Up @@ -3463,7 +3462,6 @@ describe('shallow', () => {
<Foo foo="props" />,
{
context: { foo: 'context' },
lifecycleExperimental: true,
},
);
wrapper.setState({ foo: 'baz' });
Expand Down Expand Up @@ -3519,7 +3517,7 @@ describe('shallow', () => {
return <div>foo</div>;
}
}
const wrapper = shallow(<Foo />, { lifecycleExperimental: true });
const wrapper = shallow(<Foo />);
expect(wrapper.instance().state.foo).to.equal('bar');
wrapper.setState({ foo: 'baz' });
expect(wrapper.instance().state.foo).to.equal('baz');
Expand Down Expand Up @@ -3549,7 +3547,7 @@ describe('shallow', () => {
return <div>{this.state.name}</div>;
}
}
const result = shallow(<Foo />, { lifecycleExperimental: true });
const result = shallow(<Foo />);
expect(spy).to.have.property('callCount', 1);
result.setState({ name: 'bar' });
expect(spy).to.have.property('callCount', 3);
Expand Down Expand Up @@ -3581,7 +3579,7 @@ describe('shallow', () => {
return <div>{this.state.name}</div>;
}
}
const result = shallow(<Foo />, { lifecycleExperimental: true });
const result = shallow(<Foo />);
expect(spy).to.have.property('callCount', 1);
result.setState({ name: 'bar' });
expect(spy).to.have.property('callCount', 3);
Expand Down Expand Up @@ -3621,7 +3619,6 @@ describe('shallow', () => {
<Foo foo="props" />,
{
context: { foo: 'bar' },
lifecycleExperimental: true,
},
);
expect(wrapper.instance().context.foo).to.equal('bar');
Expand Down Expand Up @@ -3680,7 +3677,6 @@ describe('shallow', () => {
<Foo />,
{
context: { foo: 'bar' },
lifecycleExperimental: true,
},
);
wrapper.setContext({ foo: 'baz' });
Expand Down Expand Up @@ -3713,7 +3709,6 @@ describe('shallow', () => {
<Foo />,
{
context: { foo: 'bar' },
lifecycleExperimental: true,
},
);
expect(spy).to.have.property('callCount', 1);
Expand Down Expand Up @@ -3750,7 +3745,6 @@ describe('shallow', () => {
<Foo />,
{
context: { foo: 'bar' },
lifecycleExperimental: true,
},
);
expect(spy).to.have.property('callCount', 1);
Expand All @@ -3771,13 +3765,13 @@ describe('shallow', () => {
return <div>foo</div>;
}
}
const wrapper = shallow(<Foo />, { lifecycleExperimental: true });
const wrapper = shallow(<Foo />);
wrapper.unmount();
expect(spy).to.have.property('callCount', 1);
});
});

it('should not call when lifecycleExperimental flag is false', () => {
it('should not call when disableLifecycleMethods flag is true', () => {
const spy = sinon.spy();
class Foo extends React.Component {
componentDidMount() {
Expand All @@ -3787,11 +3781,11 @@ describe('shallow', () => {
return <div>foo</div>;
}
}
shallow(<Foo />, { lifecycleExperimental: false });
shallow(<Foo />, { disableLifecycleMethods: true });
expect(spy).to.have.property('callCount', 0);
});

it('should call shouldComponentUpdate when lifecycleExperimental flag is false', () => {
it('should call shouldComponentUpdate when disableLifecycleMethods flag is true', () => {
const spy = sinon.spy();
class Foo extends React.Component {
constructor(props) {
Expand All @@ -3812,7 +3806,7 @@ describe('shallow', () => {
<Foo foo="foo" />,
{
context: { foo: 'foo' },
lifecycleExperimental: false,
disableLifecycleMethods: true,
},
);
expect(spy).to.have.property('callCount', 0);
Expand Down
8 changes: 4 additions & 4 deletions packages/enzyme/src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class ShallowWrapper {
this[RENDERER].render(nodes, options.context);
const instance = this[RENDERER].getNode().instance;
if (
options.lifecycleExperimental &&
!options.disableLifecycleMethods &&
instance &&
typeof instance.componentDidMount === 'function'
) {
Expand Down Expand Up @@ -277,7 +277,7 @@ class ShallowWrapper {
// make sure that componentWillReceiveProps is called before shouldComponentUpdate
let originalComponentWillReceiveProps;
if (
this[OPTIONS].lifecycleExperimental &&
!this[OPTIONS].disableLifecycleMethods &&
instance &&
typeof instance.componentWillReceiveProps === 'function'
) {
Expand All @@ -288,7 +288,7 @@ class ShallowWrapper {
// dirty hack: avoid calling shouldComponentUpdate twice
let originalShouldComponentUpdate;
if (
this[OPTIONS].lifecycleExperimental &&
!this[OPTIONS].disableLifecycleMethods &&
instance &&
typeof instance.shouldComponentUpdate === 'function'
) {
Expand All @@ -307,7 +307,7 @@ class ShallowWrapper {
instance.shouldComponentUpdate = originalShouldComponentUpdate;
}
if (
this[OPTIONS].lifecycleExperimental &&
!this[OPTIONS].disableLifecycleMethods &&
instance &&
typeof instance.componentDidUpdate === 'function'
) {
Expand Down

0 comments on commit e8296d7

Please sign in to comment.