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.

[new rule] prefer jest.doMock

See original GitHub issue

I have found using jest.doMock over jest.mock works better because it is predictable and works well with resetMocks, resetModules and restoreMocks.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
SimenBcommented, Jun 22, 2019

It won’t work with import as they’re hoisted to the top level. I’m not against adding a rule for it, though 🙂

0reactions
G-Rathcommented, Jan 1, 2022

Am closing per my previous comment

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Jest Object
Creates a new mock function. The new function has no formal parameters and when called will return undefined . This functionality also applies ......
Read more >
Difference between jest.mock and jest.doMock - Stack Overflow
jest.mock is hoisted above import when used at top level and hoisted to the the beginning of the block when used in a...
Read more >
Jest Object (API Reference) - w3resource
It will create a new mock function. The new function will have no formal parameters and when called returns undefined. This functionality will ......
Read more >
Mocking React hooks when unit testing using Jest
A general rule I like to follow is to mock only the edges of your app and these are the points of contact...
Read more >
Testing Jest Problem: Cannot mock and unmock in the same file
My solution was to create a new file just to test the catch block. ... Sounds like exactly the use case for jest.doMock....
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