From 5e5800958fd6bad1edb33110fe8b2050a7b67a76 Mon Sep 17 00:00:00 2001 From: Art Date: Thu, 15 Jun 2023 14:01:48 +0700 Subject: [PATCH] fix test --- e2e/__tests__/toMatchNamedSnapshot.test.ts | 2 +- packages/jest-snapshot/src/__tests__/printSnapshot.test.ts | 3 +++ packages/jest-snapshot/src/index.ts | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/e2e/__tests__/toMatchNamedSnapshot.test.ts b/e2e/__tests__/toMatchNamedSnapshot.test.ts index 2b385821ba73..148d5f8f8c91 100644 --- a/e2e/__tests__/toMatchNamedSnapshot.test.ts +++ b/e2e/__tests__/toMatchNamedSnapshot.test.ts @@ -94,7 +94,7 @@ test('first snapshot fails, second passes', () => { const filename = 'first-snapshot-fails-second-passes.test.js'; const template = makeTemplate(`test('named snapshots', () => { expect($1).toMatchNamedSnapshot('test-snapshot'); - expect($2).toMatchNamedSnapshot('test-snapshot'); + expect($2).toMatchNamedSnapshot('test-snapshot-2'); });`); { diff --git a/packages/jest-snapshot/src/__tests__/printSnapshot.test.ts b/packages/jest-snapshot/src/__tests__/printSnapshot.test.ts index 6689fb6ce21e..2e9bbf49dcb2 100644 --- a/packages/jest-snapshot/src/__tests__/printSnapshot.test.ts +++ b/packages/jest-snapshot/src/__tests__/printSnapshot.test.ts @@ -745,6 +745,7 @@ describe('pass false', () => { actual: format(received), count: 1, expected: undefined, + key: 'specific-not-written-multi-line 1', pass: false, }; }, @@ -773,6 +774,7 @@ describe('pass false', () => { actual: format(received), count: 2, expected: undefined, + key: 'specific-not-written-single-line 1', pass: false, }; }, @@ -860,6 +862,7 @@ describe('pass false', () => { text: 'snapshot', type, }), + key: 'change text value 1', pass: false, }; }, diff --git a/packages/jest-snapshot/src/index.ts b/packages/jest-snapshot/src/index.ts index 80b865b61ae6..bf5dbe3ac95a 100644 --- a/packages/jest-snapshot/src/index.ts +++ b/packages/jest-snapshot/src/index.ts @@ -446,10 +446,11 @@ const _toMatchSnapshot = (config: MatchSnapshotConfig) => { }); const {actual, count, expected, key, pass} = result; - if (snapshotName && key == testNameToKey(fullTestName, 1)) { + if (snapshotName && key != testNameToKey(fullTestName, 1)) { throw new Error( 'The specific snapshot name was duplicate with the other snapshot.\n\n' + - `Snapshot name: ${snapshotName}`, + `Snapshot name: ${fullTestName}\n` + + `Snapshot Key: ${key}`, ); }