-
-
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
chore(types): separate MatcherContext, MatcherUtils and MatcherState #13141
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,17 +19,21 @@ export type AsyncExpectationResult = Promise<SyncExpectationResult>; | |
|
||
export type ExpectationResult = SyncExpectationResult | AsyncExpectationResult; | ||
|
||
export type MatcherFunctionWithState< | ||
State extends MatcherState = MatcherState, | ||
export type MatcherFunctionWithContext< | ||
Context extends MatcherContext = MatcherContext, | ||
Expected extends Array<any> = [] /** TODO should be: extends Array<unknown> = [] */, | ||
> = (this: State, actual: unknown, ...expected: Expected) => ExpectationResult; | ||
> = ( | ||
this: Context, | ||
actual: unknown, | ||
...expected: Expected | ||
) => ExpectationResult; | ||
|
||
export type MatcherFunction<Expected extends Array<unknown> = []> = | ||
MatcherFunctionWithState<MatcherState, Expected>; | ||
MatcherFunctionWithContext<MatcherContext, Expected>; | ||
|
||
// TODO should be replaced with `MatcherFunctionWithContext` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mrazauskas what is this TODO for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I recall it right, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In other words, |
||
export type RawMatcherFn<State extends MatcherState = MatcherState> = { | ||
(this: State, actual: any, ...expected: Array<any>): ExpectationResult; | ||
export type RawMatcherFn<Context extends MatcherContext = MatcherContext> = { | ||
(this: Context, actual: any, ...expected: Array<any>): ExpectationResult; | ||
/** @internal */ | ||
[INTERNAL_MATCHER_FLAG]?: boolean; | ||
}; | ||
|
@@ -41,12 +45,19 @@ export type MatchersObject = { | |
export type ThrowingMatcherFn = (actual: any) => void; | ||
export type PromiseMatcherFn = (actual: any) => Promise<void>; | ||
|
||
export interface MatcherUtils { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just extracted the fields that felt more "util-y" - should I take others? |
||
dontThrow(): void; | ||
equals: EqualsFunction; | ||
utils: typeof jestMatcherUtils & { | ||
iterableEquality: Tester; | ||
subsetEquality: Tester; | ||
}; | ||
} | ||
|
||
export interface MatcherState { | ||
assertionCalls: number; | ||
currentTestName?: string; | ||
dontThrow?(): void; | ||
error?: Error; | ||
equals: EqualsFunction; | ||
expand?: boolean; | ||
expectedAssertionsNumber?: number | null; | ||
expectedAssertionsNumberError?: Error; | ||
|
@@ -56,12 +67,10 @@ export interface MatcherState { | |
promise: string; | ||
suppressedErrors: Array<Error>; | ||
testPath?: string; | ||
utils: typeof jestMatcherUtils & { | ||
iterableEquality: Tester; | ||
subsetEquality: Tester; | ||
}; | ||
} | ||
|
||
export type MatcherContext = MatcherUtils & Readonly<MatcherState>; | ||
|
||
export type AsymmetricMatcher = { | ||
asymmetricMatch(other: unknown): boolean; | ||
toString(): string; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicit generic as otherwise it inferred
MatcherContext
and didn't error whenMatcherContext
where missing