ShirlyChenLaLaLa / ShirlyChenLaLaLa.github.io

学习前端的一些记录
Other
1 stars 0 forks source link

How to test the method in component is called? #9

Open ShirlyChenLaLaLa opened 6 years ago

ShirlyChenLaLaLa commented 6 years ago
  it('Calls "onClickReload" when click "reload" button', () => {
    const loadProps = { error: true };
    const onClose = jest.fn().mockName('onClose');
    const wrapper = shallow(<LoadingComponent loadProps={ loadProps } onClose={ onClose } activeModal />);
    const instance = wrapper.instance();
    const onClickReload = jest.spyOn(instance, 'onClickReload');
    instance.forceUpdate();
    const buttonReload = wrapper.find('.loadable-component__btn-retry');
    buttonReload.simulate('click');
    expect(onClickReload).toHaveBeenCalled();
  });