Testing with React's Jest and Enzyme when async componentDidMount

后端 未结 5 1909
一整个雨季
一整个雨季 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条回答
  •  猫巷女王i
    2020-12-31 04:54

    Your test also needs to implement async, await.
    For ex:

      it('should do something', async function() {
        const wrapper = shallow();
        const result = await wrapper.instance();
        expect(result.bar).toBe(100);
      });
    

提交回复
热议问题