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

fix: make no-jest-import error message more accurate #1169

Closed
wants to merge 3 commits into from

Conversation

mmkal
Copy link

@mmkal mmkal commented Jul 19, 2022

It isn't quite accurate to say that Jest doesn't export anything. It exports the run and runCLI functions, even though it isn't generally recommended to use them (yet).

This updates the message to match the language in https://jestjs.io/docs/jest-object ("The jest object is automatically in scope within every test file").

There's also a similar update to the no-jest-import.md docs file.

It isn't quite accurate to say that Jest doesn't export anything. It exports the `run` and `runCLI` functions, even though it isn't generally recommended to use them.

This commit updates the message to match the language in https://jestjs.io/docs/jest-object ("The `jest` object is automatically in scope within every test file").

I'll follow this commit with an update to the no-jest-import.md file too.
@SimenB SimenB requested a review from G-Rath July 19, 2022 14:25
@SimenB
Copy link
Member

SimenB commented Jul 19, 2022

I'm fine with either wording, @G-Rath wdyt?

@G-Rath
Copy link
Collaborator

G-Rath commented Jul 24, 2022

tbh I think we should be tossing the rule all together as it's no longer accurate:

  • require('jest') doesn't give you an object with the same properties as what most people want (e.g. test, spyOn, fn, etc) so it should be very obvious something wrong is being done
  • now that we have @jest/globals, it is valid to import jest from there (and my understanding is that's required in ESM)
  • you can use no-restricted-imports to enforce @jest/globals isn't used, and you can set injectGlobals to false to enforce using @jest/globals

That middleone at least means the proposed new message isn't actually true, because it depends on if you have injectGlobals set.

This was referenced Aug 22, 2022
@github-actions
Copy link

🎉 This issue has been resolved in version 27.0.0-next.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This issue has been resolved in version 27.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants