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

refactor: use typed jest globals #79

Closed
wants to merge 1 commit into from
Closed

refactor: use typed jest globals #79

wants to merge 1 commit into from

Conversation

mrazauskas
Copy link
Contributor

Using a patch to play with jestjs/jest#12856. This is a small library mixing JS/TS, so a good playground.

Observations:

  1. The most notable difference from @types/jest is that just installing @types/jest makes types of globals available everywhere. If test files live inside __tests__ directories, to be precise one should opt-out in source directories through "types": [].

  2. In contrary, just installing jest does not make types available. One has to opt-in adding tsconfig.json with "types": ["jest"] in __tests__ directories. If I get it right, this would disable other globals coming from @types/*, e.g. Node typings.

  3. If test files live next to source (not in separate directories), it is harder to be precise with any opt-ins / opt-outs. In case of jest types, tsconfig.json needs "types": ["jest", "node"].

  4. If we have JS library, installing @jest/types or jest makes typings of globals available in all files. With tsconfig.json added, one has to opt-in for jest types, but @jest/types are still available globally.


Also I reworked type checks to include files of e2e and unit tests. Somehow missed it before.

Comment on lines -1 to -8
import {
afterEach,
beforeEach,
describe,
expect,
jest,
test,
} from '@jest/globals';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types are pulled from jest without any imports or third party libs. Sweet.

@mrazauskas
Copy link
Contributor Author

The useful parts were moved to #116.

@mrazauskas mrazauskas closed this Sep 27, 2022
@mrazauskas mrazauskas deleted the refactor-typed-jest-globals branch July 14, 2023 07:59
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 this pull request may close these issues.

None yet

1 participant