Skip to content

Commit d5765f7

Browse files
authoredFeb 20, 2025··
fix(expect): Correct generic MatchersObject this type in expect.extend (#7526)
1 parent 83e3d51 commit d5765f7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
 

‎packages/expect/src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export interface RawMatcherFn<T extends MatcherState = MatcherState> {
9292
export type MatchersObject<T extends MatcherState = MatcherState> = Record<
9393
string,
9494
RawMatcherFn<T>
95-
>
95+
> & ThisType<T>
9696

9797
export interface ExpectStatic
9898
extends Chai.ExpectStatic,

‎test/core/test/jest-expect.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ describe('jest-expect', () => {
246246
message: () => '',
247247
}
248248
},
249+
toBeTestedMatcherContext<T>(received: unknown, expected: T) {
250+
if (typeof this.utils?.stringify !== 'function') {
251+
throw new TypeError('this.utils.stringify is not available.')
252+
}
253+
return {
254+
pass: received === expected,
255+
message: () => 'toBeTestedMatcherContext',
256+
}
257+
},
249258
})
250259

251260
expect(5).toBeDividedBy(5)

0 commit comments

Comments
 (0)
Please sign in to comment.