如何使用Jest在react-native中测试componentWillMount?

问题描述 投票:0回答:2

我的代码如下:

export default class {
    componentWillMount=()=>{...}
    render()=>(...return...)
}

在componentWillMount函数中,我从web api获取了一些数据。现在我想创建关于它的单元测试。我该怎么办 ? ORZ ......

react-native jest
2个回答
1
投票

你不必测试componentWillMount,反应会这样做。您应该测试放在componentWillMount中的web api请求。

您可以查看此stackoverflow question以获取可能对您有所帮助的更多详细信息。


0
投票
  componentWillMount() {
    console.log(" ********** componentWillMount ******* ");
    this.apiLogic
  }
  apiLogic = () => {
    console.log("Fetch you Api ");
  }
© www.soinside.com 2019 - 2024. All rights reserved.