Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #509: pass callback on setState and setProps #1

Closed
wants to merge 3 commits into from

Conversation

alecrobins
Copy link
Owner

Resolves enzymejs#509

Due to the asynchronous nature of setState, we can't assume a wrapper.setState or wrapper.setProps (which uses setState in the setChildProps call) will act synchronously.

This PR adds callback functions to the stateState and setProps functions for full DOM rendering and setState for shallow rendering.

Example:

class Foo extends React.Component {
  constructor(props) {
    super(props);
    this.state = { id: 'foo' };
  }
  render() {
    return (
      <div className={this.state.id} />
    );
  }
}
const wrapper = mount(<Foo />);
expect(wrapper.state()).to.eql({ id: 'foo' });
wrapper.setState({ id: 'bar' }, () => {
  expect(wrapper.state()).to.eql({ id: 'bar' });
});

@alecrobins alecrobins closed this Sep 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant