-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Mocking the implementation of path.resolve
causes internal Jest errors
#14182
Comments
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Just commenting so the issue doesn't close - this error does still occur with the current latest version |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
This is nodejs/node#31852 FWIW |
@SimenB Ah I see, thanks for the context! |
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. |
Version
29.5.0
Steps to reproduce
yarn install
and thenyarn test example-valid.test.js
, which should passyarn test example-invalid.test.js
, which should report the error:yarn test
(with no passed filenames) would also fail, but in my actual project where I'm experiencing this issue, the tests would fail no matter whatExpected behavior
I expect to be able to mock
path.resolve
without having to worry about breaking the internals of JestActual behavior
I received an error stating either
Cannot find module 'jest-util'
orCannot find module 'jest-worker'
depending how I ran the tests in my projectAdditional context
I did attempt to search for this issue on Google, the Jest GitHub issue tracker, and the Jest documentation. I saw a few answers suggesting that this may be due to an incomplete installation of
jest
. However, as you can see, the tests run fine in the same environment by simply removing the permanent mock ofpath.resolve
. The test cases here might seem a bit contrived since they're doing the same thing, but in my actual project it's convenient to be able to mockpath.resolve
just once in adescribe
as I have several distinct test cases of the same function which rely on that mock.I am able to solve this issue by using a different approach (such as the
beforeEach
+mockReturnValueOnce
approach used in the example valid test file), but in general I think it would make sense that ajest
mock should not break its own ability to run tests. I have also found that mockingpath.resolve
can causerequire
s orjest.requireActual
calls to breakEnvironment
The text was updated successfully, but these errors were encountered: