Add default export for jest mocking
SmolinPavel opened this issue · comments
Add default export for jest mocking
As far as I see we can only import { detect } from 'detect-browser';
So when I try to mock this function in jest
import detectBrowser from 'detect-browser';
jest.mock('detect-browser');
there's no chance to do this in a regular way.
I think adding a simple export default { detect: ... }
could be a solution.
Thanks!
UPDATE
Found a solution:
jest.mock('detect-browser', () => ({
__esModule: true, // this property makes it work
default: 'mockedDefaultExport',
detect: jest.fn(),
}));
Hope this helps someone having the same issue :)
@SmolinPavel thanks so much for posting both the issue and the solution (in record time I might add). Feel free to close it when you are ready. It should still be searchable and thus discoverable for anyone who might have the same issue in the future.