Open bisubus opened 3 years ago
I second this. I have just spent an hour trying to debug why a manual mock isn't being used and this would be immensely useful.
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
The issue is still relevant.
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
The issue is still relevant.
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
The issue is still relevant.
🚀 Feature Proposal
The proposal is to allow to specify that
jest.mock('my-module')
should use__mocks__
or not.Motivation
jest.mock
is too magical, it's nearly always known if it's automocking or__mocks__
that is expected in a test. Silently switching between auto and manual mock injest.mock('my-module')
results in a undetermined behaviour that may not be evident and needs to be debugged.A notable example is facebook/create-react-app#7539
Example
Uses manual mock if it exists, throws an error that contains full path to expected
__mocks__/my-module.js
otherwise:Ignores
__mocks__/my-module.js
and does automocking:Pitch
Module mocking is core Jest feature and needs to be practical out of the box.