question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

5reactions
ThinkFWDcommented, Jun 22, 2018

I have the same problem, what was your solution?

0reactions
github-actions[bot]commented, May 11, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found