Last active
October 16, 2017 16:14
-
-
Save mgenov/e3d90ef501632e1fd83abded5a86403d to your computer and use it in GitHub Desktop.
Testing RN Input Component with Enzyme
This file contains hidden or 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, { Component } from 'react' | |
import { TextInput } from 'react-native' | |
import { shallow, configure } from 'enzyme' | |
import Adapter from 'enzyme-adapter-react-16' | |
import renderer from 'react-test-renderer' | |
import { SearchBar } from 'react-native-elements' | |
configure({ adapter: new Adapter() }) | |
class MyInput extends Component { | |
constructor(props) { | |
super(props) | |
this.state = { text: 'Useless Placeholder' } | |
} | |
render() { | |
return ( | |
<SearchBar | |
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }} | |
onChangeText={text => { | |
this.setState({ text }) | |
}} | |
value={this.state.text} | |
/> | |
) | |
} | |
} | |
describe('(MyInput) is ', () => { | |
it('sends notification on input changes', () => { | |
const wrapper = shallow(<MyInput />) | |
wrapper | |
.find(SearchBar) | |
.first() | |
.simulate('ChangeText', '42') | |
expect(wrapper.state()).toEqual({ text: '42' }) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment