Testing with React's Jest and Enzyme when async componentDidMount

后端 未结 5 1918
一整个雨季
一整个雨季 2020-12-31 04:30
  • react:16.3.0-alpha.1
  • jest: \"22.3.0\"
  • enzyme: 3.3.0
  • typescript: 2.7.1

code:

class Foo extends React.PureCompo         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 04:30

    Solution:

    1: use the async/await syntax.

    2: Use mount (no shallow).

    3: await async componentLifecycle.

    For ex:

        test(' ',async () => {
          const wrapper = mount(
             
          );
          await wrapper.instance().componentDidMount();
        })
    

提交回复
热议问题