0

I'm busy getting into unit testing with React, Jest and Enzyme.

I've got a component that takes a PDF File as a prop, see this interface:

interface IProps {
  file: File;
}

I'm trying to do a straight up basic test just to make sure the component renders without crashing using it's required props (i.e. the File).

Here's my test case:

describe('MyComponent', () => {
  const props = {
    file: /* How do I mock this file? */
  };

  it('renders without crashing', () => {
    mount(<MyComponent {...props} />);
  });
});

How do I mock a File for the file prop?

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Barry Michael Doyle
  • 9,333
  • 30
  • 83
  • 143
  • Hi maybe this thread can help you: https://stackoverflow.com/questions/24488985/how-to-mock-file-in-javascript – t3__rry Oct 19 '18 at 13:46

1 Answers1

0

use Mock Functions https://jestjs.io/docs/en/mock-functions

describe('MyComponent', () => {
    const props = {
    file: jest.fn()
};

it('renders without crashing', () => {
    mount(<MyComponent {...props} />);
 });
});
maqon
  • 166
  • 1
  • 6