-
-
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
ReferenceError: Cannot access 'myMock' before initialization
if test itself and 'myMock' are in different files
#11455
Comments
Does it happen if you use |
Hello, I tried Tried calling |
This is a runtime error, the babel plugin would have warned you if you didn't name it |
Hi Simen, Strangely, the mock had a different name (without I still can't quite make it function, but now it's a Typescript thing. Thanks for the help. |
Ah, probably because of ts-jest's implementation of the hoisting. |
I see, thanks for the insight! I still get lost on the internals of Jest :( |
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. |
🐛 Bug Report
Same problem as issue #10996, encountering
ReferenceError: Cannot access 'myMock' before initialization
while trying to run test on a mock imported from another file.If the mock is in the same file as the test, it runs correctly.
These two test cases are included in the repo (see below)
To Reproduce
https://github.com/dnbtr/jest-test-bug
;$ npm install
to install dependencies;$ npm test
.Expected behavior
Two tests are provided, in the following folders:
src/tests/workingTest
src/tests/buggyTest
Files on
src/adapters
andsrc/integrations
are not relevant to the issue.I hadn't time to cut the code to the bare minimum.
The workingTest should pass, the buggyTest should fail with
ReferenceError: Cannot access 'mockDynamoRepository_1' before initialization
.Both tests are identical, the difference is that the mock (DynamoRepositoryMock) was moved to a different file in the buggy test.
Uncomment lines on
src/tests/buggyTest/buggyTest.spec.ts
to see other implementations that also don't work and result in the same error.Expected output:
Link to repo
https://github.com/dnbtr/jest-test-bug
envinfo
There is no env. Repo can be used as-is.
The text was updated successfully, but these errors were encountered: