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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions docs/rules/no-jest-import.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

The `jest` object is automatically in scope within every test file. The methods
in the `jest` object help create mocks and let you control Jest's overall
behavior. It is therefore completely unnecessary to import in `jest`, as Jest
doesn't export anything in the first place.
behavior. It is therefore usually unnecessary to import in `jest`.

### Rule details

Expand All @@ -12,8 +11,13 @@ This rule reports on any importing of Jest.
To name a few: `var jest = require('jest');` `const jest = require('jest');`
`import jest from 'jest';` `import {jest as test} from 'jest';`

There is no correct usage of this code, other than to not import `jest` in the
first place.
Examples of correct code include running Jest programatically in non-CLI
environments (note that this is [not officially supported](https://github.com/facebook/jest/issues/5048)):

```js
const jest = require('jest')
jest.runCLI(...)
```

## Further Reading

Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-jest-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default createRule({
recommended: 'error',
},
messages: {
unexpectedImport: `Jest is automatically in scope. Do not import "jest", as Jest doesn't export anything.`,
unexpectedImport: `Do not import "jest". Jest is automatically in scope within every test file.`,
},
schema: [],
},
Expand Down