-
-
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
Mock factories do not support explicit TypeScript typing using imported types #7633
Comments
I tried messing with the order of babel plugins without making it work - no matter if @loganfsmyth is there any way we can make sure that our plugin is ran after Plugin source: https://github.com/facebook/jest/blob/master/packages/babel-plugin-jest-hoist/src/index.js I tried doing |
Perhaps making the |
Wow, that does the trick. Thanks once again @jeysal! I'll put together a PR |
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
Mock factories do not support explicit TypeScript typing using imported types in mock factories because hoisting happens before types are stripped.
To Reproduce
Steps to reproduce the behaviour:
In a test file, do:
Expected behavior
Since Jest does not perform any checks related to typings, it makes sense to me that type information should be stripped (and other Babel plugins should be applied) before mocks are hoisted.
As Jest claims I reference an out-of-scope "variable" (actually a type), this does not seem to be the case. To me (and @SimenB, who looked at this after I gave up), this seems like a bug.
Link to repl or repo (highly encouraged)
Simple repro with a semi-realistic case: https://github.com/theneva/jest-babel-hoist-typescript-repro
Run
npx envinfo --preset jest
The text was updated successfully, but these errors were encountered: