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

jest-globals-import: false negative when global is explicitly imported #574

Closed
puglyfe opened this issue May 10, 2024 · 0 comments · Fixed by #575
Closed

jest-globals-import: false negative when global is explicitly imported #574

puglyfe opened this issue May 10, 2024 · 0 comments · Fixed by #575

Comments

@puglyfe
Copy link
Contributor

puglyfe commented May 10, 2024

Given a file that is already importing jest globals, the current logic will actually remove the import, resulting in a ReferenceError when tests are run with the modified files.

I would expect any globals that have a corresponding ImportSpecifier would be left untouched.

Example input:

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

beforeEach(() => {
  console.log('hello world');
});

Actual output:

beforeEach(() => { // `ReferenceError: beforeEach is not defined` when running tests
  console.log('hello world');
});

Expected output:

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

beforeEach(() => {
  console.log('hello world');
});

I have a fix for this queued up if you agree with my interpretation of the intended behavior.

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.

1 participant