Skip to content

Instantly share code, notes, and snippets.

@mgenov
Last active October 16, 2017 16:14
Show Gist options
  • Select an option

  • Save mgenov/e3d90ef501632e1fd83abded5a86403d to your computer and use it in GitHub Desktop.

Select an option

Save mgenov/e3d90ef501632e1fd83abded5a86403d to your computer and use it in GitHub Desktop.

Revisions

  1. mgenov revised this gist Oct 16, 2017. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions MyInput.spec.js
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,9 @@ 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 {
    @@ -12,7 +15,7 @@ class MyInput extends Component {

    render() {
    return (
    <TextInput
    <SearchBar
    style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
    onChangeText={text => {
    this.setState({ text })
    @@ -27,7 +30,7 @@ describe('(MyInput) is ', () => {
    it('sends notification on input changes', () => {
    const wrapper = shallow(<MyInput />)
    wrapper
    .find('TextInput')
    .find(SearchBar)
    .first()
    .simulate('ChangeText', '42')
    expect(wrapper.state()).toEqual({ text: '42' })
  2. mgenov created this gist Oct 16, 2017.
    35 changes: 35 additions & 0 deletions MyInput.spec.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    import React, { Component } from 'react'
    import { TextInput } from 'react-native'
    import { shallow, configure } from 'enzyme'
    import Adapter from 'enzyme-adapter-react-16'
    configure({ adapter: new Adapter() })

    class MyInput extends Component {
    constructor(props) {
    super(props)
    this.state = { text: 'Useless Placeholder' }
    }

    render() {
    return (
    <TextInput
    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('TextInput')
    .first()
    .simulate('ChangeText', '42')
    expect(wrapper.state()).toEqual({ text: '42' })
    })
    })