0
有三件事我想弄清楚。现在我正在使用浅层渲染。我使用Enzyme和Jest。浅试React branch Jest and Enzyme
- 我想知道如何测试我的React组件中的分支。 I 想测试if-else语句(?:)的两侧。而且我不想用自己的功能把它拉出来。
- 如何在输入更改时检查this.props.myFuncFromProps(value)是否被称为 ?
- 什么是测试mapStateToProps和 mapDispatchToProps的最佳实践?
这里是我的组件会是什么样子的例子:
import React from 'react';
import MyChildComponent from 'wherever'; // This component is an input field in this example
export class MyComponent extends React.Component {
render() {
const myFunc(value) {
this.props.myFuncFromProps(value);
}
return (
<div>
{ this.props.isTrue ?
<MyChildComponent
value={this.props.value}
onChange={(value) => myFunc(value)}
/>
: null
}
</div>
);
}
}