-
-
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]: mock factory hoisting fails with 'mock' prepended variables #11862
Comments
I think we need to improve the docs - the exception is that Jest doesn't throw when parsing the file, it's not an exception to the limitation. That limitation comes from how JS works and nothing we can do about it. The error message from the code is clearer than the docs: #11455 (comment) |
- close jestjs#11862 - related to jestjs#11455
- close jestjs#11862 - related to jestjs#11455
- close jestjs#11862 - related to jestjs#11455
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
27.1.1
Steps to reproduce
npm install
npm test
ReferenceError: Cannot access 'mockExampleClient' before initialization
Expected behavior
As stated in jests docs, I expect variables prepended with
mock
to be defined outside of the mock factory without issue.Actual behavior
An error is thrown:
ReferenceError: Cannot access 'mock' before initialization
wheremock
is a variable defined outside of the moduleFactory parameter passed tojest.mock()
.Additional context
continues #10996
Environment
The text was updated successfully, but these errors were encountered: