Skip to content

Commit

Permalink
fix(expect): Correct generic MatchersObject this type in expect.extend (
Browse files Browse the repository at this point in the history
  • Loading branch information
pengooseDev authored Feb 20, 2025
1 parent 83e3d51 commit d5765f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/expect/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export interface RawMatcherFn<T extends MatcherState = MatcherState> {
export type MatchersObject<T extends MatcherState = MatcherState> = Record<
string,
RawMatcherFn<T>
>
> & ThisType<T>

export interface ExpectStatic
extends Chai.ExpectStatic,
Expand Down
9 changes: 9 additions & 0 deletions test/core/test/jest-expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,15 @@ describe('jest-expect', () => {
message: () => '',
}
},
toBeTestedMatcherContext<T>(received: unknown, expected: T) {
if (typeof this.utils?.stringify !== 'function') {
throw new TypeError('this.utils.stringify is not available.')
}
return {
pass: received === expected,
message: () => 'toBeTestedMatcherContext',
}
},
})

expect(5).toBeDividedBy(5)
Expand Down

0 comments on commit d5765f7

Please sign in to comment.