diff --git a/CHANGELOG.md b/CHANGELOG.md index 244c1fa51cec..f95d8290a652 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixes +- `[jest-jasmine2]` Stop adding `:` after an error that has no message ([#9990](https://github.com/facebook/jest/pull/9990)) + ### Chore & Maintenance ### Performance 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})}`;