Skip to content

Commit

Permalink
fix(jest-jasmine2): fix Error message (#9990)
Browse files Browse the repository at this point in the history
  • Loading branch information
bertho-zero committed May 7, 2020
1 parent b172247 commit 4bd3d4a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions packages/jest-jasmine2/src/expectationResultFactory.ts
Expand Up @@ -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})}`;
Expand Down

0 comments on commit 4bd3d4a

Please sign in to comment.