jest.mock() does not work when module name has ".js" in it
See original GitHub issue💬 Questions and Help
I am trying to mock the “react-plotly.js” module, but when i am running test files with
jest.mock("react-plotly.js")
in them, the execution fails with the following error message:
Test suite failed to run
TypeError: window.URL.createObjectURL is not a function
When testing the exact same test but with all “react-plotly.js” imports changed to “react-plotly”, the test execute fine. It seems to me like the dot in the module name is breaking the mocking.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:9
Top Results From Across the Web
jestjs - jest.mock(..) not working in 'describe' (TypeError
Jest mock is for mocking modules and the first argument is the moduleName which it has to be a valid module name (inside...
Read more >Manual Mocks - Jest
When a manual mock exists for a given module, Jest's module system will use that module when explicitly calling jest.mock('moduleName') .
Read more >Mocking a JavaScript Class with Jest, two ways to make it easier
mock() are hoisted on the top of the file. If you name this mock variable beginning with fake or spy it will not...
Read more >Mock all functions in a JavaScript module except one using Jest
There are times in a Jest test when we have a module where the ... writePlayersData() during a test run, it'll do nothing...
Read more >A guide to module mocking with Jest - Emma Goto
If you wanted to mock a imported named function, say getTime : ... wanted to change what the mocked function returned for just...
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 Free
Top 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
I have the same problem, what was your solution?
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. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.