dimanche 3 mai 2020

Jest PrettyFormatPluginError: val.getMockName is not a functionTypeError: val.getMockName is not a function

I'm using jest on my nextjs app. here is the config:

module.exports = {
  /* add jest-canvas-mock for styling issues */
  setupFiles: ['<rootDir>/jest.setup.js', 'jest-canvas-mock'],
  testPathIgnorePatterns: ['<rootDir>/_next/', '<rootDir>/node_modules/'],
  moduleNameMapper: {
    '\\.(jpg|jpeg|ico|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
      '<rootDir>/__mocks__/fileMock.js',
    '\\.(css|less|scss)$': 'identity-obj-proxy',
  },
};

this is the content of fileMock.js file

module.exports = 'test-file-stub';

and this is my test file for a component which uses sass:

it('fund should renders correctly', () => {
   const component = <ReduxProvider initialState={mockState}>
        <IntlProvider>
          <Fund />
        </IntlProvider>
      </ReduxProvider>;

    const tree = renderer.create(component).toJSON();
    expect(tree).toMatchSnapshot();
  });

and here is the error:

PrettyFormatPluginError: val.getMockName is not a functionTypeError: val.getMockName is not a function

  63 |   it('fund should renders correctly', () => {
  64 |     const tree = renderer.create(component).toJSON();
> 65 |     expect(tree).toMatchSnapshot();
     |                  ^
  66 |   });
  67 | });
  68 | 

do you have any idea what is wrong with my configuration?

Aucun commentaire:

Enregistrer un commentaire