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>
);
}
}