Skip to content

Instantly share code, notes, and snippets.

@mknabe
Last active April 27, 2018 07:24
Show Gist options
  • Save mknabe/19be7277a8612e4a9ef9e3334cca54c9 to your computer and use it in GitHub Desktop.
Save mknabe/19be7277a8612e4a9ef9e3334cca54c9 to your computer and use it in GitHub Desktop.
React testing
/*
Call a component method
https://github.com/airbnb/enzyme/issues/208#issuecomment-187313486
*/
const wrapper = shallow(<Button />); wrapper.instance().handleClick();
/*
Re-render component after calling setState
https://github.com/airbnb/enzyme/issues/450#issuecomment-225075145
*/
expect(wrapper.update().find('#counter').text()).to.equal('1');
/*
Pass props to event handler
https://github.com/airbnb/enzyme/issues/400
*/
wrapper.find('Select').simulate('change', { target: { value: 'text' }});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment