Fix failure messages for toBeRejectedWithError matcher

This commit is contained in:
Alexey Prokhorov
2019-05-03 09:37:11 +04:00
parent 35968e4a60
commit 8ab46566ac
2 changed files with 56 additions and 15 deletions

View File

@@ -33,11 +33,11 @@ getJasmineRequireObj().toBeRejectedWithError = function(j$) {
function matchError(actual, expected) {
if (!j$.isError_(actual)) {
return fail(expected, 'not rejected with Error.');
return fail(expected, 'rejected with ' + j$.pp(actual));
}
if (!(actual instanceof expected.error)) {
return fail(expected, 'rejected with type ' + j$.fnNameFor(actual.constructor) + '.');
return fail(expected, 'rejected with type ' + j$.fnNameFor(actual.constructor));
}
var actualMessage = actual.message;
@@ -50,20 +50,20 @@ getJasmineRequireObj().toBeRejectedWithError = function(j$) {
return pass(expected);
}
return fail(expected, 'rejected with ' + j$.pp(actual) + '.');
return fail(expected, 'rejected with ' + j$.pp(actual));
}
function pass(expected) {
return {
pass: true,
message: 'Expected a promise to be rejected with ' + expected.printValue + '.'
message: 'Expected a promise not to be rejected with ' + expected.printValue + ', but it was.'
};
}
function fail(expected, message) {
return {
pass: false,
message: 'Expected a promise to be rejected with ' + expected.printValue + ' but it was ' + message
message: 'Expected a promise to be rejected with ' + expected.printValue + ' but it was ' + message + '.'
};
}
@@ -82,7 +82,7 @@ getJasmineRequireObj().toBeRejectedWithError = function(j$) {
return {
error: error,
message: message,
printValue: j$.fnNameFor(error) + ': ' + j$.pp(message)
printValue: j$.fnNameFor(error) + (typeof message === 'undefined' ? '' : ': ' + j$.pp(message))
};
}
};