toMatchInlineSnapshot fails if prettier's native module deps are mocked through jest.mock
See original GitHub issue🐛 Bug Report
toMatchInlineSnapshot fails if path
module is mocked
jest.mock('path', () => ({}));
test('foo', () => {
expect({}).toMatchInlineSnapshot();
});
results in
● Test suite failed to run
TypeError: path.resolve is not a function
Run npx envinfo --preset jest
Paste the results here:
System:
OS: macOS High Sierra 10.13.5
CPU: x64 Intel(R) Core(TM) i7-6567U CPU @ 3.30GHz
Binaries:
Node: 8.9.4 - ~/.nvm/versions/node/v8.9.4/bin/node
Yarn: 1.7.0 - /usr/local/bin/yarn
npm: 5.6.0 - ~/.nvm/versions/node/v8.9.4/bin/npm
npmPackages:
jest: ^23.4.0 => 23.4.0
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (10 by maintainers)
Top Results From Across the Web
Configuring Jest
Node.js core modules, like fs , are not mocked by default. ... For example, with the following configuration jest will fail if there...
Read more >Jest: Error when trying to import Native Modules
I found the solution to this. I had been worried that perhaps the mocks weren't being tracked through all the import statement.
Read more >jest-mock | Yarn - Package Manager
Creates a new module mocker that generates mocks as if they were created in an environment with the given global object.
Read more >De-mystifying Jest Snapshot Test Mocks | by Albert Brand
I hope you now have a clear understanding of what's happening when a module is mocked with Jest and that you're able to...
Read more >Snapshot Testing - Jest
Snapshot tests are a useful tool when you want to make sure your UI doesn?t change unexpectedly.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for explaining @aaronabramov! Also, unfortunately yes I can reproduce this on master.
Here is the test I added to
e2e/__tests__/to_match_inline_snapshot.test.js
and reproduces the bug on latest master.I’m trying to dig into this. I’ve got a test that reproduces the bug in
e2e/__tests__/to_match_inline_snapshot.test.js
.The error is coming from the compiled
node_modules/prettier/third-party.js
and originally from this line incosmiconfig
dependency. Thats the code thats trying to run whenTypeError: path.resolve is not a function
happens.node_modules/prettier/prettier-bin.js
is right now using these native modulesI’m assuming
jest.mock
will overrider any of the above. I’m unsure how to actually fix this issue (looking at https://github.com/facebook/jest/pull/6687 for inspiration) but I’ll keep digging. I’d appreciate any input from folks with more context.update jest.mock only causes failure on some of them