Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bennycode
Created December 14, 2017 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennycode/823a0532f6783ab275453e85c4ea14ed to your computer and use it in GitHub Desktop.
Save bennycode/823a0532f6783ab275453e85c4ea14ed to your computer and use it in GitHub Desktop.
Testing form input elements with enzyme
import React from 'react'; // 16.2.0
import {mount} from 'enzyme'; // 3.2.0
it('does something', () => {
class TestInput extends React.Component {
constructor(props) {
super(props);
this.state = {
inputValue: 'before',
};
}
render() {
return <input value={this.state.inputValue} onChange={event => this.setState({inputValue: event.target.value})} />
}
}
const wrapper = mount(<TestInput />);
const input = wrapper.find('input');
input.simulate('change', {target: {value: 'after'}});
expect(wrapper.state('inputValue')).toBe('after');
expect(input.instance().value).toBe('after');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment