React Enzyme - Test `componentDidMount` Async Call

后端 未结 3 2035
迷失自我
迷失自我 2020-12-09 11:28

everyone.

I\'m having weird issues with testing a state update after an async call happening in componentDidMount.

Here\'s my component code:

3条回答
  •  悲&欢浪女
    2020-12-09 12:24

    I had a look at https://www.npmjs.com/package/request and figured out that the 'body' parameter is missing from the callback.

    It should look like

    ...
    request('https://api.github.com/users', (err, res, body) => {
        if (!err && res.statusCode === 200) {
          this.setState({
            usersList: body.slice(0)
          });
        }
    ...
    

提交回复
热议问题