From 3a450de69f5d6888c8cc5a12fad712b0cf990346 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Tue, 9 Jul 2019 17:34:58 +0200 Subject: [PATCH] FIX unit tests & add a null-check before getting the array length of new property filesRemovedList --- .../jest-reporters/src/__tests__/get_snapshot_summary.test.js | 4 ++++ .../jest-reporters/src/__tests__/summary_reporter.test.js | 3 +++ packages/jest-reporters/src/get_snapshot_summary.ts | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/jest-reporters/src/__tests__/get_snapshot_summary.test.js b/packages/jest-reporters/src/__tests__/get_snapshot_summary.test.js index c2a911d22365..fb76b156b1e2 100644 --- a/packages/jest-reporters/src/__tests__/get_snapshot_summary.test.js +++ b/packages/jest-reporters/src/__tests__/get_snapshot_summary.test.js @@ -21,6 +21,7 @@ test('creates a snapshot summary', () => { didUpdate: false, filesAdded: 1, filesRemoved: 1, + filesRemovedList: [], filesUnmatched: 1, filesUpdated: 1, matched: 2, @@ -49,6 +50,7 @@ test('creates a snapshot summary after an update', () => { didUpdate: true, filesAdded: 1, filesRemoved: 1, + filesRemovedList: [], filesUnmatched: 1, filesUpdated: 1, unchecked: 1, @@ -75,6 +77,7 @@ it('creates a snapshot summary with multiple snapshot being written/updated', () didUpdate: false, filesAdded: 2, filesRemoved: 2, + filesRemovedList: [], filesUnmatched: 2, filesUpdated: 2, unchecked: 2, @@ -105,6 +108,7 @@ it('returns nothing if there are no updates', () => { didUpdate: false, filesAdded: 0, filesRemoved: 0, + filesRemovedList: [], filesUnmatched: 0, filesUpdated: 0, unchecked: 0, diff --git a/packages/jest-reporters/src/__tests__/summary_reporter.test.js b/packages/jest-reporters/src/__tests__/summary_reporter.test.js index b4b56758a6c7..ead47477fc61 100644 --- a/packages/jest-reporters/src/__tests__/summary_reporter.test.js +++ b/packages/jest-reporters/src/__tests__/summary_reporter.test.js @@ -70,6 +70,7 @@ test('snapshots needs update with yarn test', () => { numTotalTestSuites: 1, numTotalTests: 1, snapshot: { + filesRemovedList: [], filesUnmatched: 1, total: 2, uncheckedKeysByFile: [], @@ -98,6 +99,7 @@ test('snapshots all have results (no update)', () => { didUpdate: false, filesAdded: 1, filesRemoved: 1, + filesRemovedList: [], filesUnmatched: 1, filesUpdated: 1, matched: 2, @@ -134,6 +136,7 @@ test('snapshots all have results (after update)', () => { didUpdate: true, filesAdded: 1, filesRemoved: 1, + filesRemovedList: [], filesUnmatched: 1, filesUpdated: 1, matched: 2, diff --git a/packages/jest-reporters/src/get_snapshot_summary.ts b/packages/jest-reporters/src/get_snapshot_summary.ts index 26bb44587364..214963b0edf4 100644 --- a/packages/jest-reporters/src/get_snapshot_summary.ts +++ b/packages/jest-reporters/src/get_snapshot_summary.ts @@ -84,7 +84,7 @@ export default ( ); } } - if (snapshots.filesRemovedList.length) { + if (snapshots.filesRemovedList && snapshots.filesRemovedList.length) { const [head, ...tail] = snapshots.filesRemovedList; summary.push(` ${DOWN_ARROW} ${DOT}${formatTestPath(globalConfig, head)}`);