Pavel Nasovich's Blog

The Moderately Enthusiastic Programmer

Today I Learned: Mocking multiple named exports in Jest

Posted at — Dec 7, 2018

I know only one way.

Mock it:

jest.mock('path/to/some/module', () => ({
    someNamedExportFromModule: jest.fn()
  }));

Then import it:

import {someNamedExportFromModule} from 'path/to/some/module';

Setup value to return:

someNamedExportFromModule.mockReturnValue('someValue');

???

You are the best.

gl hf

comments powered by Disqus