Created
December 14, 2017 13:12
-
-
Save bennycode/823a0532f6783ab275453e85c4ea14ed to your computer and use it in GitHub Desktop.
Testing form input elements with enzyme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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