mercredi 8 février 2017

testing react component with enzyme

Vote count: 1

Say I have the following component:

export default class CustomInput extends PureComponent {
  render () {
    return (
      <input type='text' value={this.props.value || ''} onChange={this.props.changeHandler} placeholder={this.props.placeholderValue} />
    )
  }
}

CustomInput.propTypes = {
  value: PropTypes.string,
  placeholderValue: PropTypes.string,
  changeHandler: PropTypes.func.isRequired
}

Which I attempt to test as follows:

test('input renders correctly', () => {
    const handler = jest.fn()
    const display = shallow(<CustomInput value='foo' placeholderValue='bar' changeHandler={handler}/>)
    })

This fails with:

TypeError: Cannot read property 'contextTypes' of undefined

Any help would be much appreciated!

asked 36 secs ago

Let's block ads! (Why?)



testing react component with enzyme

Aucun commentaire:

Enregistrer un commentaire