From 6b1a6ed70f7a42d7740c01f3852593bcb54d7333 Mon Sep 17 00:00:00 2001 From: Art Date: Mon, 10 Apr 2023 17:45:14 +0700 Subject: [PATCH] fixes properties --- .../__snapshots__/printSnapshot.test.ts.snap | 12 ++---------- .../src/__tests__/printSnapshot.test.ts | 17 +---------------- packages/jest-snapshot/src/index.ts | 2 +- 3 files changed, 4 insertions(+), 27 deletions(-) diff --git a/packages/jest-snapshot/src/__tests__/__snapshots__/printSnapshot.test.ts.snap b/packages/jest-snapshot/src/__tests__/__snapshots__/printSnapshot.test.ts.snap index 383adf911fbf..f6d7649f705e 100644 --- a/packages/jest-snapshot/src/__tests__/__snapshots__/printSnapshot.test.ts.snap +++ b/packages/jest-snapshot/src/__tests__/__snapshots__/printSnapshot.test.ts.snap @@ -60,17 +60,9 @@ Expected properties has value: [Function] exports[`matcher error toMatchNamedSnapshot Expected properties must be an object (null) with snapshot name 1`] = ` expect(received).toMatchNamedSnapshot(properties) -Snapshot state must be initialized - -Snapshot state has value: undefined -`; - -exports[`matcher error toMatchNamedSnapshot Expected properties must be an object (null) without snapshot name 1`] = ` -expect(received).toMatchNamedSnapshot(properties) - -Snapshot state must be initialized +Matcher error: Expected properties must be an object -Snapshot state has value: undefined +Expected properties has value: null `; exports[`matcher error toMatchNamedSnapshot Snapshot state must be initialized 1`] = ` diff --git a/packages/jest-snapshot/src/__tests__/printSnapshot.test.ts b/packages/jest-snapshot/src/__tests__/printSnapshot.test.ts index 037c32f66775..64582f78111f 100644 --- a/packages/jest-snapshot/src/__tests__/printSnapshot.test.ts +++ b/packages/jest-snapshot/src/__tests__/printSnapshot.test.ts @@ -311,21 +311,6 @@ describe('matcher error', () => { }).toThrowErrorMatchingSnapshot(); }); - test('Expected properties must be an object (null) without snapshot name', () => { - const context = { - isNot: false, - promise: '', - } as Context; - const properties = null; - const snapshotName = - 'toMatchNamedSnapshot Expected properties must be an object (null) without snapshot name'; - - expect(() => { - // @ts-expect-error: Testing runtime error - toMatchNamedSnapshot.call(context, received, snapshotName, properties); - }).toThrowErrorMatchingSnapshot(); - }); - test('Expected properties must be an object (array)', () => { const context = { isNot: false, @@ -333,7 +318,7 @@ describe('matcher error', () => { } as Context; const properties: Array = []; const snapshotName = - 'toMatchNamedSnapshot Expected properties must be an object (null) without snapshot name'; + 'toMatchNamedSnapshot Expected properties must be an object (array)'; expect(() => { toMatchNamedSnapshot.call(context, received, snapshotName, properties); diff --git a/packages/jest-snapshot/src/index.ts b/packages/jest-snapshot/src/index.ts index e88f1fa15945..d8d4093a826e 100644 --- a/packages/jest-snapshot/src/index.ts +++ b/packages/jest-snapshot/src/index.ts @@ -233,7 +233,7 @@ export const toMatchNamedSnapshot: MatcherFunctionWithContext< > = function (received, snapshotName, properties?) { const matcherName = 'toMatchNamedSnapshot'; - if (properties) { + if (properties !== undefined) { if ( Array.isArray(properties) || typeof properties !== 'object' ||