我的代码如下:
export default class {
componentWillMount=()=>{...}
render()=>(...return...)
}
在componentWillMount函数中,我从web api获取了一些数据。现在我想创建关于它的单元测试。我该怎么办 ? ORZ ......
你不必测试componentWillMount
,反应会这样做。您应该测试放在componentWillMount中的web api请求。
您可以查看此stackoverflow question以获取可能对您有所帮助的更多详细信息。
componentWillMount() {
console.log(" ********** componentWillMount ******* ");
this.apiLogic
}
apiLogic = () => {
console.log("Fetch you Api ");
}