mercredi 18 septembre 2019

Why this spyOn doesn't called after clicking the button?

I'm writing test for the button. I wanna check that button click simulation call the function. But my spyOn have not been called. What's a mistake?

  describe('download-button tests', () => {
        let nextState;
        let wrapper:any;
        beforeEach(() => {
          wrapper = setupmount();
          nextState = {
          ...initialState,
          checkAttrs:false,
          disableAttr: false,
          disableTable: false,
          disableRadio: false,
          selectedDB: '1',
          selectedCode:'1',
          entityType: '',
          selectedEntity: "1864296",
        }
          wrapper.setState(nextState);
        })
              test('should handle the click event', () => {
                const spy = jest.spyOn(wrapper.instance(), 'handleDownload');
                wrapper.instance().forceUpdate();
                let btn = wrapper.find('button').first();
                btn.simulate('click');
                expect(spy).toHaveBeenCalled();
                });
          });

Aucun commentaire:

Enregistrer un commentaire