-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot jest.mock('module/sub/directory/file')
#226
Comments
I have the same problem. Is there any progress? |
is it still an issue? var invariant = require('fbjs/lib/invariant');
describe('invariant', function() {
it('is mocked', function() {
expect(invariant._isMockFunction).toBe(true);
});
}); and it worked |
I'm going to have a look at the thing today in the evening. Nevertheless, I think the problem has gone because jest was rewritten, particularly a mocking part. |
Hi @DmitriiAbramov, I've created a repo where you can reproduce the problem: https://github.com/ivantsov/jest-mock-nested-folders. Just run There is a Hope it helps. |
@ivantsov i think the issue here is that you don't have the here is what i tried in your repo:
and the test passed |
But if I just create |
that is true.. |
Yep, seems like any attempt to mock any require('module/submodule') mapped to mocks/module/submodule is failing on my side. In the meantime I use jest.mock + require.requireActual |
Yeah the solution here is to use jest.mock. We are unlikely to extend manual mocks to have sub folders for now but I might revisit this decision in the future. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'm requiring
invariant
in my tested code like so:In my tests,
'req/lib/invariant'
does not get mocked, even when I explicitly calljest.mock('react/lib/invariant')
To get around this unexpected behavior, I
require('./invariant')
, which looks like this:Is there any way to
require('sub/modules')
?The text was updated successfully, but these errors were encountered: