2
votes

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!

1

1 Answers

1
votes

So it turns out that the problem was with my import. Specifically, removing the autoimport like so:

import CustomInput from './index'

rather than

import {CustomInput} from './index'

An explanation of what caused the problem in the first place would be more than welcome