-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Feature]: Replace @types/jest
's expect
implementation with @jest/expect
#12424
Comments
Very good move. What I was playing with roughly looked like this:
declare const jest: import('jest').Jest;
declare const beforeAll: import('jest').TestFrameworkGlobals['beforeAll'];
declare const beforeEach: import('jest').TestFrameworkGlobals['beforeEach'];
declare const afterAll: import('jest').TestFrameworkGlobals['afterAll'];
declare const afterEach: import('jest').TestFrameworkGlobals['afterEach'];
declare const describe: import('jest').TestFrameworkGlobals['describe'];
declare const fdescribe: import('jest').TestFrameworkGlobals['fdescribe'];
declare const xdescribe: import('jest').TestFrameworkGlobals['xdescribe'];
declare const test: import('jest').TestFrameworkGlobals['test'];
declare const xtest: import('jest').TestFrameworkGlobals['xtest'];
declare const it: import('jest').TestFrameworkGlobals['it'];
declare const fit: import('jest').TestFrameworkGlobals['fit'];
declare const xit: import('jest').TestFrameworkGlobals['xit'];
declare const expect: import('jest').JestExpect;
"version": "28.0.0",
"peerDependencies": {
"jest": "^28.0.0",
} The idea was to turn So importing Might be there is still a chance that something would drift, or overlap, or go wrong. What you think? (; |
Yeah, that's essentially what DefinitelyTyped/DefinitelyTyped#44365 does, and is what I want as end state. However, that loses a bunch of I'd like to start with just replacing parts of |
Perhaps we could try it out with some I was playing |
Couldn’t recall in which of branches I had them. Something like this seems to be working (importing from current exports): declare const jest: import('@jest/environment').Jest;
declare namespace jest {
export type MockedFunction<T> = import('jest-mock').MockedFunction<T>;
export type MockedClass<T> = import('jest-mock').MockedClass<T>;
// ...
} |
Ah nice, that'd be awesome. Would also be cool if we had the same in Jest 🙂 We should probably port over the type tests in DefinitivelyTyped to this repo well |
For anyone following along, we've replace our own usage of I'd still love for |
@SimenB I think I stumbled on this issue since I want to make |
If this issue is resolved, yes 🙂 As of now |
This ticket is just like how I like a good bbq... low n slow... |
Actually there is no need to have {
"devDependencies": {
"@types/jest": "npm:@jest/test-globals@*"
}
} At the moment |
@SimenB What you think about the above idea? I was thinking And {
"devDependencies": {
"@types/jest": "npm:@jest/globals@*"
}
} Ah.. Of course, Here is somewhat similar solution I tried to put together: mattphillips/jest-expect-message#70 |
But if we could end up exporting the globals from the |
Right... Now I recall that we already talked about this in #12411 |
If we started publishing We're still missing some types etc., but easy enough to add any missing later |
Importing In a way they should publish major releases. Does that mean that those libraries should also bump their majors? Will everyone agree? For instance, some Might be I am overthinking. In any case, it sounded that: "devDependencies": {
"@types/jest": "npm:@jest/test-globals@*"
} is a solution to provide global typings without even touching |
Hmm, yeah. Good question. Is it breaking in a way that we should fix? I guess we could also set the version in the deps of the packages that depend on Or if the other packages on DT only e.g. add new matchers, they'd ideally extend |
Hm.. if I get it right, the dependency on another A real case is here: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/heft-jest Here The |
🚀 Feature Proposal
People might not want to use the globals (
expect
,test
etc.) Jest provides (either because of ESM or just a preference). And because Jest is written in TypeScript, when doing e.g.import {expect} from '@jest/globals'
all built in matchers are typed. However, if you use some matchers from the community (such asjest-extended
), they augment the matchers from@types/jest
instead ofexpect
(or@jest/expect
). If instead all libraries augmented the actualexpect
types, the imported matcher would be typed correctly.However, this flips the problem - now people using the globals no longer get custom matchers typed! The solution to this problem is to make
@jest/types
use@jest/expect
instead of shipping its own types for this.This issue is for tracking the work that needs to be done before releasing Jest 28 stable so there's a single source of truth - the source code.
I have started: https://github.com/SimenB/DefinitelyTyped/tree/jest-expect
We need to make sure the tests pass. Most breakage is due to the tests using e.g.
jest.InverseMatchers
etc - I don't think that's super useful? I might be wrong though, in which case we should expose more of those types fromexpect
and/or@jest/expect
.(note that running tests is "impossible" until microsoft/DefinitelyTyped-tools#411 is merged. I rannpm install
manually insidetypes/jest
to see errors in the tests in my IDE)/cc @mrazauskas
The text was updated successfully, but these errors were encountered: