-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Invalid variable access: _jsxFileName #9896
Comments
Same here, I had to disable the new JSX transform for my tests to run. |
In my case, it was solved by creating a jest.mock('../folder/myModule', () => {
return {
__esModule: true,
default: function myModule() {
return <div>My Module</div>
},
}
}) I just pointed to the manual mock: // Mock import
jest.mock('../folder/myModule')
// Folder structure
../folder/__mock__/myModule
//File in "../folder/__mock__/myModule"
import React from 'react'
function MyModule() {
return <div>My Module</div>
}
export default Cover Reference: https://jestjs.io/docs/en/manual-mocks |
@yann-combarnous, how did you disabled new JSX transform? I tried adding |
Fixed in |
Jest is still pinned currently:
Will require us to bump the version. Edit: I read your comment more closely @SimenB. I assume |
Yep, just removing Bumping up the Jest version in CRA would be nice though. I plan to release one final v26 patch tomorrow before starting work on v27 - shipping the lastest 26 by default in CRA would be nice. |
Having this issue as well but none of the solutions here worked. I am using CRA "react-scripts": "4.0.2", @yann-combarnous I tried setting the env variable:
Didn't work for me. @lc-brunomonteiro I tried creating a manual mock. But also didn't work @SimenB I already have [email protected] installed & the corresponding version of I tried clearing my yarn.lock and re-installing anyway, but did not help. I tried updating to [email protected] (also didn't solve it). any ideas why this would still be happening with [email protected]? |
If none of the suggested fixes works for you you probably have a completely different issue |
@SimenB figured it out. It was due to my location of before:
after
I'll leave this here, since this is the only issue I found with the error I got. Hope it helps some one else. |
weird, I'd have thought that worked fine as the variable should be in the outer scope already. Can you create an issue (with a reproduction) in the Jest repo? |
Using |
Describe the bug
My tests are failing because I have some Jest mocks that use JSX. The error is
Invalid variable access: _jsxFileName
.It seems to be related to jestjs/jest#10690
Did you try recovering your dependencies?
Yes.
Which terms did you search for in User Guide?
_jsxFileName
Environment
Steps to reproduce
jest.mock('./someModule', () => () => <div />)
Expected behavior
Tests should work.
Actual behavior
Reproducible demo
(Paste the link to an example project and exact instructions to reproduce the issue.)
The text was updated successfully, but these errors were encountered: