From acb42b03ccccf9f8a6fdc4dc959ac86ef5d78c00 Mon Sep 17 00:00:00 2001 From: Art Date: Fri, 16 Jun 2023 09:47:25 +0700 Subject: [PATCH] fix the test --- .../src/__tests__/throwMatcher.test.ts | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/jest-snapshot/src/__tests__/throwMatcher.test.ts b/packages/jest-snapshot/src/__tests__/throwMatcher.test.ts index 3846092742da..4c639d1b19e5 100644 --- a/packages/jest-snapshot/src/__tests__/throwMatcher.test.ts +++ b/packages/jest-snapshot/src/__tests__/throwMatcher.test.ts @@ -92,16 +92,26 @@ describe('throw matcher from promise', () => { }); describe('toThrowErrorMatchingNamedSnapshot', () => { + const mockedNamedMatch = jest.fn(() => ({ + actual: 'coconut', + expected: 'coconut', + key: 'snapshot name 1', + })); + + const mockedNamedContext = { + snapshotState: {match: mockedNamedMatch}, + } as unknown as Context; + it('can take error', () => { toThrowErrorMatchingNamedSnapshot.call( - mockedContext, + mockedNamedContext, new Error('coco'), 'snapshot name', true, ); - expect(mockedMatch).toHaveBeenCalledTimes(1); - expect(mockedMatch).toHaveBeenCalledWith( + expect(mockedNamedMatch).toHaveBeenCalledTimes(1); + expect(mockedNamedMatch).toHaveBeenCalledWith( expect.objectContaining({received: 'coco', testName: 'snapshot name'}), ); }); @@ -110,14 +120,14 @@ describe('throw matcher from promise', () => { class CustomError extends Error {} toThrowErrorMatchingNamedSnapshot.call( - mockedContext, + mockedNamedContext, new CustomError('nut'), 'snapshot name', true, ); - expect(mockedMatch).toHaveBeenCalledTimes(1); - expect(mockedMatch).toHaveBeenCalledWith( + expect(mockedNamedMatch).toHaveBeenCalledTimes(1); + expect(mockedNamedMatch).toHaveBeenCalledWith( expect.objectContaining({received: 'nut', testName: 'snapshot name'}), ); });