From 3ff2036a21f854719c0eeda13ffd0f66eee81a46 Mon Sep 17 00:00:00 2001 From: Bertho Date: Wed, 6 May 2020 17:44:17 +0200 Subject: [PATCH 1/3] fix(jest-jasmine2): fix Error message --- .../src/__tests__/expectationResultFactory.test.ts | 12 ++++++++++++ .../jest-jasmine2/src/expectationResultFactory.ts | 3 +++ 2 files changed, 15 insertions(+) diff --git a/packages/jest-jasmine2/src/__tests__/expectationResultFactory.test.ts b/packages/jest-jasmine2/src/__tests__/expectationResultFactory.test.ts index fdf940eab04c..59cebccb4cd9 100644 --- a/packages/jest-jasmine2/src/__tests__/expectationResultFactory.test.ts +++ b/packages/jest-jasmine2/src/__tests__/expectationResultFactory.test.ts @@ -55,6 +55,18 @@ describe('expectationResultFactory', () => { expect(result.message).toEqual('Error: Expected `Pass`, received `Fail`.'); }); + it('returns the error name if the error message is empty', () => { + const options = { + actual: 'Fail', + error: new Error(), + expected: 'Pass', + matcherName: 'testMatcher', + passed: false, + }; + const result = expectationResultFactory(options); + expect(result.message).toEqual('Error'); + }); + it('returns the result if failed (with `error` as a string).', () => { const options = { actual: 'Fail', diff --git a/packages/jest-jasmine2/src/expectationResultFactory.ts b/packages/jest-jasmine2/src/expectationResultFactory.ts index d7c8e6221520..d4533fdf3dcc 100644 --- a/packages/jest-jasmine2/src/expectationResultFactory.ts +++ b/packages/jest-jasmine2/src/expectationResultFactory.ts @@ -25,6 +25,9 @@ function messageFormatter({error, message, passed}: Options) { typeof error.message === 'string' && typeof error.name === 'string' ) { + if (error.message === '') { + return error.name; + } return `${error.name}: ${error.message}`; } return `thrown: ${prettyFormat(error, {maxDepth: 3})}`; From 31457cf7bf8b48bd34d8bfd444ec3e930125aef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Berthommier?= Date: Thu, 7 May 2020 11:46:47 +0200 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 244c1fa51cec..ce249c42a3ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixes +- `[jest-jasmine2]` Stop adding `: ` after an error that has no message + ### Chore & Maintenance ### Performance From 76660f02351dbf9185c3132865a63724cedda7c7 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 7 May 2020 14:01:52 +0200 Subject: [PATCH 3/3] link pr in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce249c42a3ed..f95d8290a652 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Fixes -- `[jest-jasmine2]` Stop adding `: ` after an error that has no message +- `[jest-jasmine2]` Stop adding `:` after an error that has no message ([#9990](https://github.com/facebook/jest/pull/9990)) ### Chore & Maintenance