From d5765f71b3d269cb2d3a06666a5070372e21e62e Mon Sep 17 00:00:00 2001 From: Pengoose Date: Thu, 20 Feb 2025 10:41:23 +0900 Subject: [PATCH] fix(expect): Correct generic MatchersObject this type in expect.extend (#7526) --- packages/expect/src/types.ts | 2 +- test/core/test/jest-expect.test.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/expect/src/types.ts b/packages/expect/src/types.ts index 792a8b84a..0993110ee 100644 --- a/packages/expect/src/types.ts +++ b/packages/expect/src/types.ts @@ -92,7 +92,7 @@ export interface RawMatcherFn { export type MatchersObject = Record< string, RawMatcherFn -> +> & ThisType export interface ExpectStatic extends Chai.ExpectStatic, diff --git a/test/core/test/jest-expect.test.ts b/test/core/test/jest-expect.test.ts index 93566aec3..8d4c9cbf3 100644 --- a/test/core/test/jest-expect.test.ts +++ b/test/core/test/jest-expect.test.ts @@ -246,6 +246,15 @@ describe('jest-expect', () => { message: () => '', } }, + toBeTestedMatcherContext(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) -- 2.51.2