improved error msg on toBeRehectedWithError and all other built-in async matchers

This commit is contained in:
Andrei D
2024-12-22 17:43:47 +02:00
parent 1f1e1209d2
commit a1591da25d
12 changed files with 26 additions and 12 deletions

View File

@@ -12,7 +12,9 @@ getJasmineRequireObj().toBePending = function(j$) {
return {
compare: function(actual) {
if (!j$.isPromiseLike(actual)) {
throw new Error('Expected toBePending to be called on a promise.');
throw new Error(
`Expected toBePending to be called on a promise but was on a ${typeof actual}.`
);
}
const want = {};
return Promise.race([actual, Promise.resolve(want)]).then(

View File

@@ -14,7 +14,9 @@ getJasmineRequireObj().toBeRejected = function(j$) {
return {
compare: function(actual) {
if (!j$.isPromiseLike(actual)) {
throw new Error('Expected toBeRejected to be called on a promise.');
throw new Error(
`Expected toBeRejected to be called on a promise but was on a ${typeof actual}.`
);
}
return actual.then(
function() {

View File

@@ -16,7 +16,7 @@ getJasmineRequireObj().toBeRejectedWith = function(j$) {
compare: function(actualPromise, expectedValue) {
if (!j$.isPromiseLike(actualPromise)) {
throw new Error(
'Expected toBeRejectedWith to be called on a promise.'
`Expected toBeRejectedWith to be called on a promise but was on a ${typeof actualPromise}.`
);
}

View File

@@ -19,7 +19,7 @@ getJasmineRequireObj().toBeRejectedWithError = function(j$) {
compare: function(actualPromise, arg1, arg2) {
if (!j$.isPromiseLike(actualPromise)) {
throw new Error(
'Expected toBeRejectedWithError to be called on a promise.'
`Expected toBeRejectedWithError to be called on a promise but was on a ${typeof actualPromise}.`
);
}

View File

@@ -14,7 +14,9 @@ getJasmineRequireObj().toBeResolved = function(j$) {
return {
compare: function(actual) {
if (!j$.isPromiseLike(actual)) {
throw new Error('Expected toBeResolved to be called on a promise.');
throw new Error(
`Expected toBeResolved to be called on a promise but was on a ${typeof actual}.`
);
}
return actual.then(

View File

@@ -15,7 +15,9 @@ getJasmineRequireObj().toBeResolvedTo = function(j$) {
return {
compare: function(actualPromise, expectedValue) {
if (!j$.isPromiseLike(actualPromise)) {
throw new Error('Expected toBeResolvedTo to be called on a promise.');
throw new Error(
`Expected toBeResolvedTo to be called on a promise but was on a ${typeof actualPromise}.`
);
}
function prefix(passed) {