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
@jest/globals doesn't seem to work with jest.mock #10060
Comments
This makes it easier for TypeScript to typecheck our tests, rather relying on `any`-typed globals. Unfortunately, it was not possible to `import { jest } from "@jest/globals"` in files that also call jest.mock(). This was reported here: jestjs/jest#10060
This makes it easier for TypeScript to typecheck our tests, rather relying on `any`-typed globals. For more details, see https://jestjs.io/blog/2020/05/05/jest-26#a-new-way-to-consume-jest---jestglobals Unfortunately, it was not possible to `import { jest } from "@jest/globals"` in files that also call jest.mock(). This was reported here: jestjs/jest#10060
Possibly related to the fact that ts-jest doesnβt have the hoisting implementation yet like Babel-jest, see kulshekhar/ts-jest#1593 |
This makes it easier for TypeScript to typecheck our tests, rather relying on `any`-typed globals. For more details, see https://jestjs.io/blog/2020/05/05/jest-26#a-new-way-to-consume-jest---jestglobals Unfortunately, it was not possible to `import { jest } from "@jest/globals"` in files that also call jest.mock(). This was reported here: jestjs/jest#10060
Yep, this will only work properly with |
This makes it easier for TypeScript to typecheck our tests, rather relying on `any`-typed globals. For more details, see https://jestjs.io/blog/2020/05/05/jest-26#a-new-way-to-consume-jest---jestglobals Unfortunately, it was not possible to `import { jest } from "@jest/globals"` in files that also call jest.mock(). This was reported here: jestjs/jest#10060
This makes it easier for TypeScript to typecheck our tests, rather relying on `any`-typed globals. For more details, see https://jestjs.io/blog/2020/05/05/jest-26#a-new-way-to-consume-jest---jestglobals Unfortunately, it was not possible to `import { jest } from "@jest/globals"` in files that also call jest.mock(). This was reported here: jestjs/jest#10060
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
When importing
jest
from@jest/globals
, and runningjest.mock
, I get:That's what I get in the minimal reproduction repo. In my regular code, I instead get this error:
To Reproduce
Steps to reproduce the behavior:
git clone git@github.com:Vinnl/ts-jest-repro.git --branch globals-mock
(Note that this is not on the master branch.)
npm install
npm test
This is a repository with Jest and ts-jest setup. The problematic code is:
Expected behavior
The test to run successfully.
Link to repl or repo (highly encouraged)
git clone git@github.com:Vinnl/ts-jest-repro.git --branch globals-mock
envinfo
The text was updated successfully, but these errors were encountered: