当你想在componentDidMount()
React 生命周期方法上测试一个函数被调用时该怎么做。基本上组件代码如下所示:
state = {
randomStateToPopulate: []
};
// Test componentDidMount
componentDidMount() {
this.randomFunction();
}
randomFunction= () => {
listRandomData().then(({ data }) => {
this.setState({ randomStateToPopulate: data });
});
};
那么,你如何实际测试这个案例?