enzyme

Testing with React's Jest and Enzyme when simulated clicks call a function that calls a promise

北战南征 提交于 2019-11-26 14:36:49
问题 React v15.1.0 Jest v12.1.1 Enzyme v2.3.0 I'm trying to figure out how to test a component that calls a promise in a function invoked by a click. I was expecting Jest's runAllTicks() function to help me out here, but it doesn't seem to be executing the promise. Component: import React from 'react'; import Promise from 'bluebird'; function doSomethingWithAPromise() { return new Promise((resolve) => { setTimeout(() => { resolve(); }, 50); }); } export default class AsyncTest extends React

Enzyme simulate an onChange event

心已入冬 提交于 2019-11-26 14:26:29
问题 I'm testing a react component with Mocha and Enzyme. Here is the component (shortened for simplicity of course): class New extends React.Component { // shortened for simplicity handleChange(event) { // handle changing state of input const target = event.target; const value = target.value; const name = target.name this.setState({[name]: value}) } render() { return( <div> <form onSubmit={this.handleSubmit}> <div className="form-group row"> <label className="col-2 col-form-label form-text">Poll

When should you use render and shallow in Enzyme / React tests?

泪湿孤枕 提交于 2019-11-26 11:52:30
问题 prior to posting this question, I tried to search in sqa stackexchange but I found no post about shallow and render there, so I hope someone can help me out here. When should I use shallow and render in testing react components? Based on the airbnb docs, I\'ve made some opinions on the difference of the two: Since shallow is testing components as a unit , so it should be used for \'parent\' components. (ex. Tables, Wrappers, etc.) Render is for child components. The reason I asked this