samedi 16 février 2019

When testing a React component with Enzyme is it better to use simulate or to call the method directly on the instance()?

If you have a component like this

class Editor extends Component {
  handleChange() {
    // some code
  }

  render() {
     <div>
       <input className="Editor" onChange={this.handleChange} />
     </div>
  }
}

Is it better to test the handle change by simulating the change event with simulate like this:

wrapper.simulate('change', { // })

Or by calling the method directly by using instance:

wrapper.instance().handleChange()

Aucun commentaire:

Enregistrer un commentaire