jeudi 30 mai 2019

Check if native FileReader is trigerred after input click

I am trying to write a test based on this anwer: How can I test a change handler for a file-type input in React using Jest/Enzyme?

 it('checks if native file reader is triggered', () => {
    const componentWrapper = mountWithIntl(<UploadFileButton   {...fakeProps} />);
    const fileContents = 'file contents';
    const readAsText = jest.fn();
    const addEventListener = jest.fn((_, evtHandler) => {
      evtHandler();
    });
    const dummyFileReader = {
    addEventListener,
    readAsText,
    result: fileContents,
    };
    window.FileReader = jest.fn(() => dummyFileReader);
    componentWrapper.find('input').simulate('click');
    expect(FileReader).toHaveBeenCalled();
  });

I get an error:

expect(jest.fn()).toHaveBeenCalled()

Expected mock function to have been called.

Aucun commentaire:

Enregistrer un commentaire