Skip to content
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

Doesn't work if injectGlobals is false #116

Open
dhardtke opened this issue Apr 24, 2023 · 1 comment · May be fixed by #119
Open

Doesn't work if injectGlobals is false #116

dhardtke opened this issue Apr 24, 2023 · 1 comment · May be fixed by #119

Comments

@dhardtke
Copy link

In our project we do not want to enable injection of globals such as test, describe, etc.

See https://jestjs.io/docs/cli#--injectglobals

If injectGlobals is set to false, jest-mock-extended doesn't work:

jest is not defined
ReferenceError: jest is not defined
    at calledWithFn (<userdir>\node_modules\jest-mock-extended\lib\CalledWithFn.js:25:16)
    at Object.get (<userdir>\node_modules\jest-mock-extended\lib\Mock.js:90:45)
    at mockReset (<userdir>\backend\node_modules\jest-mock-extended\lib\Mock.js:42:17)

The issue is that jest-mock-extended is relying on the global "jest" object to exist.

I tried explicitly adding

import { jest } from '@jest/globals';

but jest-mock-extended uses types from @types/jest which provides different definitions than the ones returned by @jest/globals.

@skovhus
Copy link
Contributor

skovhus commented May 15, 2023

It makes a lot of sense for this library to move from @types/jest to @jest/globals + make @jest/globals a peer dependency.

The only challenge seems to be the jest.Mock type that changed interface, so this one requires some library changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants