Skip to content

Instantly share code, notes, and snippets.

@mgenov
Last active October 16, 2017 16:14
Show Gist options
  • Save mgenov/e3d90ef501632e1fd83abded5a86403d to your computer and use it in GitHub Desktop.
Save mgenov/e3d90ef501632e1fd83abded5a86403d to your computer and use it in GitHub Desktop.
Testing RN Input Component with Enzyme
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