Skip to content

Commit

Permalink
[Tests] add test for mount
Browse files Browse the repository at this point in the history
  • Loading branch information
chenesan committed Jan 19, 2019
1 parent 370be71 commit 070a708
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Expand Up @@ -5407,6 +5407,42 @@ describeWithDOM('mount', () => {
}],
]);
});

it('nextState passed into SCU should be different with this.state even GDSFP return new state', () => {
class SimpleComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
value: props.value,
};
}

static getDerivedStateFromProps(props, state) {
if (props.value === state.value) {
return null;
}

return {
value: props.value,
};
}

shouldComponentUpdate(nextProps, nextState) {
const shouldUpdate = nextState.value !== this.state.value;
return shouldUpdate;
}

render() {
return (
<input value={this.props.value} />
);
}
}
const wrapper = mount(<SimpleComponent value="initial" />);
expect(wrapper.find('input').prop('value')).to.equal('initial');
wrapper.setProps({ value: 'updated' });
expect(wrapper.find('input').prop('value')).to.equal('updated');
});
});

describeIf(is('>= 16'), 'componentDidCatch', () => {
Expand Down

0 comments on commit 070a708

Please sign in to comment.