From 4ff13793dec6dc2da42c297c62c7f3ddce18af67 Mon Sep 17 00:00:00 2001 From: cpojer Date: Thu, 4 May 2017 11:34:39 +0100 Subject: [PATCH] Tests + updateSnapshot fixes. --- .../__snapshots__/snapshot-test.js.snap | 11 +++- .../__tests__/snapshot-serializers-test.js | 6 +- integration_tests/__tests__/snapshot-test.js | 64 +++++++++++++++---- .../__tests__/toMatchSnapshot-test.js | 53 ++++++++------- .../toThrowErrorMatchingSnapshot-test.js | 32 ++++------ packages/jest-cli/src/TestRunner.js | 7 +- packages/jest-cli/src/__tests__/watch-test.js | 2 +- packages/jest-cli/src/watch.js | 2 +- .../src/__tests__/TestReconciler-test.js | 6 +- packages/jest-jasmine2/src/index.js | 10 ++- packages/jest-snapshot/src/State.js | 22 ++++--- .../src/__tests__/AsymmetricMatcher-test.js | 18 ++---- 12 files changed, 133 insertions(+), 100 deletions(-) diff --git a/integration_tests/__tests__/__snapshots__/snapshot-test.js.snap b/integration_tests/__tests__/__snapshots__/snapshot-test.js.snap index bbd998778a55..90db2bdc908c 100644 --- a/integration_tests/__tests__/__snapshots__/snapshot-test.js.snap +++ b/integration_tests/__tests__/__snapshots__/snapshot-test.js.snap @@ -36,6 +36,15 @@ Ran all test suites. " `; +exports[`Snapshot Validation does not save snapshots in CI mode by default 1`] = ` +"Test Suites: 3 failed, 3 total +Tests: 7 failed, 2 passed, 9 total +Snapshots: 9 failed, 9 total +Time: <> +Ran all test suites. +" +`; + exports[`Snapshot Validation updates the snapshot when a test removes some snapshots 1`] = ` "Test Suites: 3 passed, 3 total Tests: 9 passed, 9 total @@ -72,7 +81,7 @@ Ran all test suites. " `; -exports[`Snapshot works as expected 1`] = ` +exports[`Snapshot stores new snapshots on the first run 1`] = ` "Test Suites: 2 passed, 2 total Tests: 5 passed, 5 total Snapshots: 5 added, 5 total diff --git a/integration_tests/__tests__/snapshot-serializers-test.js b/integration_tests/__tests__/snapshot-serializers-test.js index eea69cd2e89d..de6a03a2559e 100644 --- a/integration_tests/__tests__/snapshot-serializers-test.js +++ b/integration_tests/__tests__/snapshot-serializers-test.js @@ -17,7 +17,11 @@ const snapshotsDir = path.resolve(testDir, '__tests__/__snapshots__'); const snapshotPath = path.resolve(snapshotsDir, 'snapshot-test.js.snap'); const runAndAssert = () => { - const result = runJest.json('snapshot-serializers', ['--no-cache']); + const result = runJest.json('snapshot-serializers', [ + '-w=1', + '--ci=false', + '--no-cache', + ]); const json = result.json; expect(json.numTotalTests).toBe(7); expect(json.numPassedTests).toBe(7); diff --git a/integration_tests/__tests__/snapshot-test.js b/integration_tests/__tests__/snapshot-test.js index a34b5aa67981..4563b9bd0497 100644 --- a/integration_tests/__tests__/snapshot-test.js +++ b/integration_tests/__tests__/snapshot-test.js @@ -100,8 +100,8 @@ describe('Snapshot', () => { beforeEach(cleanup); afterAll(cleanup); - it('works as expected', () => { - const result = runJest.json('snapshot', []); + it('stores new snapshots on the first run', () => { + const result = runJest.json('snapshot', ['-w=1', '--ci=false']); const json = result.json; expect(json.numTotalTests).toBe(5); @@ -122,7 +122,11 @@ describe('Snapshot', () => { it('works with escaped characters', () => { // Write the first snapshot - let result = runJest('snapshot-escape', ['snapshot-test.js']); + let result = runJest('snapshot-escape', [ + '-w=1', + '--ci=false', + 'snapshot-test.js', + ]); let stderr = result.stderr.toString(); expect(stderr).toMatch('1 snapshot written'); @@ -136,7 +140,12 @@ describe('Snapshot', () => { const newTestData = initialTestData + testData; fs.writeFileSync(snapshotEscapeTestFile, newTestData, 'utf8'); - result = runJest('snapshot-escape', ['snapshot-test.js']); + result = runJest('snapshot-escape', [ + '-w=1', + '--ci=false', + '--updateSnapshot', + 'snapshot-test.js', + ]); stderr = result.stderr.toString(); expect(stderr).toMatch('1 snapshot written'); @@ -145,7 +154,11 @@ describe('Snapshot', () => { // Now let's check again if everything still passes. // If this test doesn't pass, some snapshot data was not properly escaped. - result = runJest('snapshot-escape', ['snapshot-test.js']); + result = runJest('snapshot-escape', [ + '-w=1', + '--ci=false', + 'snapshot-test.js', + ]); stderr = result.stderr.toString(); expect(stderr).not.toMatch('Snapshot Summary'); @@ -155,14 +168,22 @@ describe('Snapshot', () => { it('works with escaped regex', () => { // Write the first snapshot - let result = runJest('snapshot-escape', ['snapshot-escape-regex.js']); + let result = runJest('snapshot-escape', [ + '-w=1', + '--ci=false', + 'snapshot-escape-regex.js', + ]); let stderr = result.stderr.toString(); expect(stderr).toMatch('2 snapshots written in 1 test suite.'); expect(result.status).toBe(0); expect(extractSummary(stderr).summary).toMatchSnapshot(); - result = runJest('snapshot-escape', ['snapshot-escape-regex.js']); + result = runJest('snapshot-escape', [ + '-w=1', + '--ci=false', + 'snapshot-escape-regex.js', + ]); stderr = result.stderr.toString(); // Make sure we aren't writing a snapshot this time which would @@ -175,6 +196,8 @@ describe('Snapshot', () => { it('works with template literal subsitutions', () => { // Write the first snapshot let result = runJest('snapshot-escape', [ + '-w=1', + '--ci=false', 'snapshot-escape-substitution-test.js', ]); let stderr = result.stderr.toString(); @@ -184,6 +207,8 @@ describe('Snapshot', () => { expect(extractSummary(stderr).summary).toMatchSnapshot(); result = runJest('snapshot-escape', [ + '-w=1', + '--ci=false', 'snapshot-escape-substitution-test.js', ]); stderr = result.stderr.toString(); @@ -200,8 +225,19 @@ describe('Snapshot', () => { fs.writeFileSync(copyOfTestPath, originalTestContent); }); + it('does not save snapshots in CI mode by default', () => { + const result = runJest.json('snapshot', ['-w=1', '--ci=true']); + + expect(result.json.success).toBe(false); + expect(result.json.numTotalTests).toBe(9); + expect(result.json.snapshot.added).toBe(0); + expect(result.json.snapshot.total).toBe(9); + const stderr = result.stderr.toString(); + expect(extractSummary(stderr).summary).toMatchSnapshot(); + }); + it('works on subsequent runs without `-u`', () => { - const firstRun = runJest.json('snapshot', []); + const firstRun = runJest.json('snapshot', ['-w=1', '--ci=false']); const content = require(snapshotOfCopy); expect(content).not.toBe(undefined); @@ -220,12 +256,12 @@ describe('Snapshot', () => { }); it('deletes the snapshot if the test suite has been removed', () => { - const firstRun = runJest.json('snapshot', []); + const firstRun = runJest.json('snapshot', ['-w=1', '--ci=false']); fs.unlinkSync(copyOfTestPath); const content = require(snapshotOfCopy); expect(content).not.toBe(undefined); - const secondRun = runJest.json('snapshot', ['-u']); + const secondRun = runJest.json('snapshot', ['-w=1', '--ci=false', '-u']); expect(firstRun.json.numTotalTests).toBe(9); expect(secondRun.json.numTotalTests).toBe(5); @@ -240,10 +276,10 @@ describe('Snapshot', () => { }); it('deletes a snapshot when a test does removes all the snapshots', () => { - const firstRun = runJest.json('snapshot', []); + const firstRun = runJest.json('snapshot', ['-w=1', '--ci=false']); fs.writeFileSync(copyOfTestPath, emptyTest); - const secondRun = runJest.json('snapshot', ['-u']); + const secondRun = runJest.json('snapshot', ['-w=1', '--ci=false', '-u']); fs.unlinkSync(copyOfTestPath); expect(firstRun.json.numTotalTests).toBe(9); @@ -259,7 +295,7 @@ describe('Snapshot', () => { }); it('updates the snapshot when a test removes some snapshots', () => { - const firstRun = runJest.json('snapshot', []); + const firstRun = runJest.json('snapshot', ['-w=1', '--ci=false']); fs.unlinkSync(copyOfTestPath); const beforeRemovingSnapshot = getSnapshotOfCopy(); @@ -270,7 +306,7 @@ describe('Snapshot', () => { '.not.toBe(undefined)', ), ); - const secondRun = runJest.json('snapshot', ['-u']); + const secondRun = runJest.json('snapshot', ['-w=1', '--ci=false', '-u']); fs.unlinkSync(copyOfTestPath); expect(firstRun.json.numTotalTests).toBe(9); diff --git a/integration_tests/__tests__/toMatchSnapshot-test.js b/integration_tests/__tests__/toMatchSnapshot-test.js index 459de5611fc9..4750f2aec2d2 100644 --- a/integration_tests/__tests__/toMatchSnapshot-test.js +++ b/integration_tests/__tests__/toMatchSnapshot-test.js @@ -26,13 +26,13 @@ test('basic support', () => { { makeTests(TESTS_DIR, {[filename]: template(['{apple: "original value"}'])}); - const {stderr, status} = runJest(DIR, [filename]); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('1 snapshot written in 1 test suite.'); expect(status).toBe(0); } { - const {stderr, status} = runJest(DIR, [filename]); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('Snapshots: 1 passed, 1 total'); expect(stderr).not.toMatch('1 snapshot written in 1 test suite.'); expect(status).toBe(0); @@ -40,13 +40,18 @@ test('basic support', () => { { makeTests(TESTS_DIR, {[filename]: template(['{apple: "updated value"}'])}); - const {stderr, status} = runJest(DIR, [filename]); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('Received value does not match stored snapshot'); expect(status).toBe(1); } { - const {stderr, status} = runJest(DIR, [filename, '-u']); + const {stderr, status} = runJest(DIR, [ + '-w=1', + '--ci=false', + filename, + '-u', + ]); expect(stderr).toMatch('1 snapshot updated in 1 test suite.'); expect(status).toBe(0); } @@ -54,29 +59,27 @@ test('basic support', () => { test('error thrown before snapshot', () => { const filename = 'error-thrown-before-snapshot-test.js'; - const template = makeTemplate( - `test('snapshots', () => { + const template = makeTemplate(`test('snapshots', () => { expect($1).toBeTruthy(); expect($2).toMatchSnapshot(); - });`, - ); + });`); { makeTests(TESTS_DIR, {[filename]: template(['true', '{a: "original"}'])}); - const {stderr, status} = runJest(DIR, [filename]); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('1 snapshot written in 1 test suite.'); expect(status).toBe(0); } { - const {stderr, status} = runJest(DIR, [filename]); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('Snapshots: 1 passed, 1 total'); expect(status).toBe(0); } { makeTests(TESTS_DIR, {[filename]: template(['false', '{a: "original"}'])}); - const {stderr, status} = runJest(DIR, [filename]); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).not.toMatch('1 obsolete snapshot found'); expect(status).toBe(1); } @@ -84,23 +87,21 @@ test('error thrown before snapshot', () => { test('first snapshot fails, second passes', () => { const filename = 'first-snapshot-fails-second-passes-test.js'; - const template = makeTemplate( - `test('snapshots', () => { + const template = makeTemplate(`test('snapshots', () => { expect($1).toMatchSnapshot(); expect($2).toMatchSnapshot(); - });`, - ); + });`); { makeTests(TESTS_DIR, {[filename]: template([`'apple'`, `'banana'`])}); - const {stderr, status} = runJest(DIR, [filename]); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('2 snapshots written in 1 test suite.'); expect(status).toBe(0); } { makeTests(TESTS_DIR, {[filename]: template([`'kiwi'`, `'banana'`])}); - const {stderr, status} = runJest(DIR, [filename]); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('Received value does not match stored snapshot'); expect(stderr).toMatch('- "apple"\n + "kiwi"'); expect(stderr).not.toMatch('1 obsolete snapshot found'); @@ -110,27 +111,25 @@ test('first snapshot fails, second passes', () => { test('does not mark snapshots as obsolete in skipped tests', () => { const filename = 'no-obsolete-if-skipped-test.js'; - const template = makeTemplate( - `test('snapshots', () => { + const template = makeTemplate(`test('snapshots', () => { expect(true).toBe(true); }); $1('will be skipped', () => { expect({a: 6}).toMatchSnapshot(); }); - `, - ); + `); { makeTests(TESTS_DIR, {[filename]: template(['test'])}); - const {stderr, status} = runJest(DIR, [filename]); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('1 snapshot written in 1 test suite.'); expect(status).toBe(0); } { makeTests(TESTS_DIR, {[filename]: template(['test.skip'])}); - const {stderr, status} = runJest(DIR, [filename]); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).not.toMatch('1 obsolete snapshot found'); expect(status).toBe(0); } @@ -138,16 +137,14 @@ test('does not mark snapshots as obsolete in skipped tests', () => { test('accepts custom snapshot name', () => { const filename = 'accept-custom-snapshot-name-test.js'; - const template = makeTemplate( - `test('accepts custom snapshot name', () => { + const template = makeTemplate(`test('accepts custom snapshot name', () => { expect(true).toMatchSnapshot('custom-name'); }); - `, - ); + `); { makeTests(TESTS_DIR, {[filename]: template()}); - const {stderr, status} = runJest(DIR, [filename]); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('1 snapshot written in 1 test suite.'); expect(status).toBe(0); } diff --git a/integration_tests/__tests__/toThrowErrorMatchingSnapshot-test.js b/integration_tests/__tests__/toThrowErrorMatchingSnapshot-test.js index a5f5ce3b0b2e..93867b68b1b5 100644 --- a/integration_tests/__tests__/toThrowErrorMatchingSnapshot-test.js +++ b/integration_tests/__tests__/toThrowErrorMatchingSnapshot-test.js @@ -20,17 +20,15 @@ afterAll(() => cleanup(TESTS_DIR)); test('works fine when function throws error', () => { const filename = 'works-fine-when-function-throws-error-test.js'; - const template = makeTemplate( - `test('works fine when function throws error', () => { + const template = makeTemplate(`test('works fine when function throws error', () => { expect(() => { throw new Error('apple'); }) .toThrowErrorMatchingSnapshot(); }); - `, - ); + `); { makeTests(TESTS_DIR, {[filename]: template()}); - const {stderr, status} = runJest(DIR, [filename]); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('1 snapshot written in 1 test suite.'); expect(status).toBe(0); } @@ -38,16 +36,14 @@ test('works fine when function throws error', () => { test(`throws the error if tested function didn't throw error`, () => { const filename = 'throws-if-tested-function-did-not-throw-test.js'; - const template = makeTemplate( - `test('throws the error if tested function did not throw error', () => { + const template = makeTemplate(`test('throws the error if tested function did not throw error', () => { expect(() => {}).toThrowErrorMatchingSnapshot(); }); - `, - ); + `); { makeTests(TESTS_DIR, {[filename]: template()}); - const {stderr, status} = runJest(DIR, [filename]); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch(`Expected the function to throw an error.`); expect(status).toBe(1); } @@ -55,17 +51,15 @@ test(`throws the error if tested function didn't throw error`, () => { test('does not accept arguments', () => { const filename = 'does-not-accept-arguments-test.js'; - const template = makeTemplate( - `test('does not accept arguments', () => { + const template = makeTemplate(`test('does not accept arguments', () => { expect(() => { throw new Error('apple'); }) .toThrowErrorMatchingSnapshot('foobar'); }); - `, - ); + `); { makeTests(TESTS_DIR, {[filename]: template()}); - const {stderr, status} = runJest(DIR, [filename]); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('Matcher does not accept any arguments.'); expect(status).toBe(1); } @@ -73,16 +67,14 @@ test('does not accept arguments', () => { test('cannot be used with .not', () => { const filename = 'cannot-be-used-with-not-test.js'; - const template = makeTemplate( - `test('cannot be used with .not', () => { + const template = makeTemplate(`test('cannot be used with .not', () => { expect('').not.toThrowErrorMatchingSnapshot(); }); - `, - ); + `); { makeTests(TESTS_DIR, {[filename]: template()}); - const {stderr, status} = runJest(DIR, [filename]); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch( 'Jest: `.not` cannot be used with `.toThrowErrorMatchingSnapshot()`.', ); diff --git a/packages/jest-cli/src/TestRunner.js b/packages/jest-cli/src/TestRunner.js index 7d67215ee967..1452f3f4a42f 100644 --- a/packages/jest-cli/src/TestRunner.js +++ b/packages/jest-cli/src/TestRunner.js @@ -140,10 +140,9 @@ class TestRunner { ); aggregatedResults.snapshot.filesRemoved += status.filesRemoved; }); - aggregatedResults.snapshot.didUpdate = - this._globalConfig.updateSnapshot === 'all'; - aggregatedResults.snapshot.failure = !!(!this._globalConfig - .updateSnapshot && + const updateAll = this._globalConfig.updateSnapshot === 'all'; + aggregatedResults.snapshot.didUpdate = updateAll; + aggregatedResults.snapshot.failure = !!(!updateAll && (aggregatedResults.snapshot.unchecked || aggregatedResults.snapshot.unmatched || aggregatedResults.snapshot.filesRemoved)); diff --git a/packages/jest-cli/src/__tests__/watch-test.js b/packages/jest-cli/src/__tests__/watch-test.js index 8b2b05781d55..7842fb750384 100644 --- a/packages/jest-cli/src/__tests__/watch-test.js +++ b/packages/jest-cli/src/__tests__/watch-test.js @@ -142,7 +142,7 @@ describe('Watch mode flows', () => { stdin.emit(KEYS.U); expect(runJestMock.mock.calls[0][0]).toEqual({ - updateSnapshot: true, + updateSnapshot: 'all', watch: true, }); diff --git a/packages/jest-cli/src/watch.js b/packages/jest-cli/src/watch.js index 35937b273eb1..ff25e409775f 100644 --- a/packages/jest-cli/src/watch.js +++ b/packages/jest-cli/src/watch.js @@ -174,7 +174,7 @@ const watch = ( startRun(); break; case KEYS.U: - startRun({updateSnapshot: true}); + startRun({updateSnapshot: 'all'}); break; case KEYS.A: updateArgv(argv, 'watchAll', { diff --git a/packages/jest-editor-support/src/__tests__/TestReconciler-test.js b/packages/jest-editor-support/src/__tests__/TestReconciler-test.js index 8ec02216d382..4a336913d2d4 100644 --- a/packages/jest-editor-support/src/__tests__/TestReconciler-test.js +++ b/packages/jest-editor-support/src/__tests__/TestReconciler-test.js @@ -47,12 +47,10 @@ describe('Test Reconciler', () => { expect(status.line).toEqual(12); const errorMessage = 'Expected value to be falsy, instead received true'; expect(status.terseMessage).toEqual(errorMessage); - expect(status.shortMessage).toEqual( - `Error: expect(received).toBeFalsy() + expect(status.shortMessage).toEqual(`Error: expect(received).toBeFalsy() Expected value to be falsy, instead received - true`, - ); + true`); }); }); }); diff --git a/packages/jest-jasmine2/src/index.js b/packages/jest-jasmine2/src/index.js index 26d2f935156a..2077b09cda3d 100644 --- a/packages/jest-jasmine2/src/index.js +++ b/packages/jest-jasmine2/src/index.js @@ -98,12 +98,10 @@ function jasmine2( env.execute(); return reporter .getResults() - .then(results => - addSnapshotData(results, snapshotState, globalConfig.updateSnapshot), - ); + .then(results => addSnapshotData(results, snapshotState)); } -const addSnapshotData = (results, snapshotState, updateSnapshot) => { +const addSnapshotData = (results, snapshotState) => { results.testResults.forEach(({fullName, status}) => { if (status === 'pending' || status === 'failed') { // if test is skipped or failed, we don't want to mark @@ -113,11 +111,11 @@ const addSnapshotData = (results, snapshotState, updateSnapshot) => { }); const uncheckedCount = snapshotState.getUncheckedCount(); - if (updateSnapshot) { + if (uncheckedCount) { snapshotState.removeUncheckedKeys(); } - const status = snapshotState.save(updateSnapshot); + const status = snapshotState.save(); results.snapshot.fileDeleted = status.deleted; results.snapshot.added = snapshotState.added; results.snapshot.matched = snapshotState.matched; diff --git a/packages/jest-snapshot/src/State.js b/packages/jest-snapshot/src/State.js index d015b2729ca1..ec5d7078a8e0 100644 --- a/packages/jest-snapshot/src/State.js +++ b/packages/jest-snapshot/src/State.js @@ -75,18 +75,18 @@ class SnapshotState { this._snapshotData[key] = receivedSerialized; } - save(shouldUpdate: SnapshotUpdateState) { + save() { + const isEmpty = Object.keys(this._snapshotData).length === 0; const status = { deleted: false, saved: false, }; - const isEmpty = Object.keys(this._snapshotData).length === 0; if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) { saveSnapshotFile(this._snapshotData, this._snapshotPath); status.saved = true; } else if (isEmpty && fs.existsSync(this._snapshotPath)) { - if (shouldUpdate === 'all') { + if (this._updateSnapshot === 'all') { fs.unlinkSync(this._snapshotPath); } status.deleted = true; @@ -100,7 +100,7 @@ class SnapshotState { } removeUncheckedKeys(): void { - if (this._uncheckedKeys.size) { + if (this._updateSnapshot === 'all' && this._uncheckedKeys.size) { this._dirty = true; this._uncheckedKeys.forEach(key => delete this._snapshotData[key]); this._uncheckedKeys.clear(); @@ -132,11 +132,17 @@ class SnapshotState { this._snapshotData[key] = receivedSerialized; } + // These are the conditions on when to write snapshots: + // * There's no snapshot file in a non-CI environment. + // * There is a snapshot file and we decided to update the snapshot. + // * There is a snapshot file, but it doesn't have this snaphsot. + // These are the conditions on when not to write snapshots: + // * The update flag is set to 'none'. + // * There's no snapshot file or a file without this snapshot on a CI environment. if ( - !fs.existsSync(this._snapshotPath) || // there's no snapshot file - (hasSnapshot && this._updateSnapshot === 'all') || // there is a file, but we're updating - (!hasSnapshot && - (this._updateSnapshot === 'new' || this._updateSnapshot === 'all')) // there is a file, but it doesn't have this snaphsot + (hasSnapshot && this._updateSnapshot === 'all') || + ((!hasSnapshot || !fs.existsSync(this._snapshotPath)) && + (this._updateSnapshot === 'new' || this._updateSnapshot === 'all')) ) { if (this._updateSnapshot === 'all') { if (!pass) { diff --git a/packages/pretty-format/src/__tests__/AsymmetricMatcher-test.js b/packages/pretty-format/src/__tests__/AsymmetricMatcher-test.js index 3c6525ebe00b..c07c73b0933d 100644 --- a/packages/pretty-format/src/__tests__/AsymmetricMatcher-test.js +++ b/packages/pretty-format/src/__tests__/AsymmetricMatcher-test.js @@ -65,21 +65,17 @@ test(`anything()`, () => { test(`arrayContaining()`, () => { const result = prettyFormat(expect.arrayContaining([1, 2]), options); - expect(result).toEqual( - `ArrayContaining [ + expect(result).toEqual(`ArrayContaining [ 1, 2, -]`, - ); +]`); }); test(`objectContaining()`, () => { const result = prettyFormat(expect.objectContaining({a: 'test'}), options); - expect(result).toEqual( - `ObjectContaining { + expect(result).toEqual(`ObjectContaining { "a": "test", -}`, - ); +}`); }); test(`stringContaining(string)`, () => { @@ -113,8 +109,7 @@ test(`supports multiple nested asymmetric matchers`, () => { }, options, ); - expect(result).toEqual( - `Object { + expect(result).toEqual(`Object { "test": Object { "nested": ObjectContaining { "a": ArrayContaining [ @@ -129,8 +124,7 @@ test(`supports multiple nested asymmetric matchers`, () => { }, }, }, -}`, - ); +}`); }); test(`supports minified output`, () => {