How to spy componentWillMount using jest and enzyme

后端 未结 5 1517
無奈伤痛
無奈伤痛 2020-12-31 13:07

I am trying to test whether componentWillMount was called and for that my test is

test(\'calls `componentWillMount` before rendering\', () => {
  let fn =         


        
5条回答
  •  再見小時候
    2020-12-31 13:53

    Try this:

    test('calls `componentWillMount` before rendering', () => {
      const onWillMount = jest.fn();
      SomeComponent.prototype.componentWillMount = onWillMount;
      mount();
    
      expect(onWillMount).toBeCalled();
    });
    

提交回复
热议问题