Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jest-jasmine2): fix Error message #9990

Merged
merged 3 commits into from May 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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