You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to upgrade to Next 12 and cannot get my tests to pass as something strange is going on with jest.mock
If I use jest.mock to mock next/router and require it from my test or indeed my project the mock works as expected. However, if I require the router into another module the original router is required, not the mock.
I also tried to mock next/dist/client/script and found similar behavior so I don't think this is limited to the router. Adding my own file to the next/dist/client directory and it can be mocked fine. Changing the contents of one of the existing files to match my own test file in there did not though. I was unable to find anything in the package that made these files special and so that is a far as I was able to investigate.
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
What version of Next.js are you using?
12.0.7
What version of Node.js are you using?
14.17.6
What browser are you using?
N/A
What operating system are you using?
macOS
How are you deploying your application?
jest
Describe the Bug
I'm trying to upgrade to Next 12 and cannot get my tests to pass as something strange is going on with
jest.mock
If I use
jest.mock
to mocknext/router
and require it from my test or indeed my project the mock works as expected. However, if I require the router into another module the original router is required, not the mock.I also tried to mock
next/dist/client/script
and found similar behavior so I don't think this is limited to the router. Adding my own file to thenext/dist/client
directory and it can be mocked fine. Changing the contents of one of the existing files to match my own test file in there did not though. I was unable to find anything in the package that made these files special and so that is a far as I was able to investigate.Expected Behavior
The router should be mocked everywhere.
To Reproduce
node_modules/my-module/index.js
app.js
tests/routerMock.test.js
The text was updated successfully, but these errors were encountered: