Include rejection details in failure messages for toBeResolved and toBeResolvedWith
[#178559119]
This commit is contained in:
@@ -4535,7 +4535,7 @@ getJasmineRequireObj().toBeResolved = function(j$) {
|
||||
* @example
|
||||
* return expectAsync(aPromise).toBeResolved();
|
||||
*/
|
||||
return function toBeResolved() {
|
||||
return function toBeResolved(matchersUtil) {
|
||||
return {
|
||||
compare: function(actual) {
|
||||
if (!j$.isPromiseLike(actual)) {
|
||||
@@ -4546,8 +4546,15 @@ getJasmineRequireObj().toBeResolved = function(j$) {
|
||||
function() {
|
||||
return { pass: true };
|
||||
},
|
||||
function() {
|
||||
return { pass: false };
|
||||
function(e) {
|
||||
return {
|
||||
pass: false,
|
||||
message:
|
||||
'Expected a promise to be resolved but it was ' +
|
||||
'rejected with ' +
|
||||
matchersUtil.pp(e) +
|
||||
'.'
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -4602,10 +4609,14 @@ getJasmineRequireObj().toBeResolvedTo = function(j$) {
|
||||
};
|
||||
}
|
||||
},
|
||||
function() {
|
||||
function(e) {
|
||||
return {
|
||||
pass: false,
|
||||
message: prefix(false) + ' but it was rejected.'
|
||||
message:
|
||||
prefix(false) +
|
||||
' but it was rejected with ' +
|
||||
matchersUtil.pp(e) +
|
||||
'.'
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
@@ -96,8 +96,8 @@ describe('AsyncExpectation', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = {
|
||||
buildFailureMessage: function() {
|
||||
return 'failure message';
|
||||
pp: function(val) {
|
||||
return val.toString();
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
@@ -114,7 +114,8 @@ describe('AsyncExpectation', function() {
|
||||
expect(addExpectationResult).toHaveBeenCalledWith(
|
||||
false,
|
||||
jasmine.objectContaining({
|
||||
message: 'Some context: failure message'
|
||||
message:
|
||||
'Some context: Expected a promise to be resolved but it was rejected with rejected.'
|
||||
})
|
||||
);
|
||||
});
|
||||
@@ -144,7 +145,8 @@ describe('AsyncExpectation', function() {
|
||||
false,
|
||||
jasmine.objectContaining({
|
||||
message:
|
||||
"Some context: Expected a promise to be resolved to 'a' but it was rejected."
|
||||
"Some context: Expected a promise to be resolved to 'a' " +
|
||||
"but it was rejected with 'b'."
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -15,12 +15,19 @@ describe('toBeResolved', function() {
|
||||
it('fails if the actual is rejected', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
pp: jasmineUnderTest.makePrettyPrinter([])
|
||||
}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolved(matchersUtil),
|
||||
actual = Promise.reject('AsyncExpectationSpec rejection');
|
||||
actual = Promise.reject(new Error('AsyncExpectationSpec rejection'));
|
||||
|
||||
return matcher.compare(actual).then(function(result) {
|
||||
expect(result).toEqual(jasmine.objectContaining({ pass: false }));
|
||||
expect(result).toEqual({
|
||||
pass: false,
|
||||
message:
|
||||
'Expected a promise to be resolved but it was rejected ' +
|
||||
'with Error: AsyncExpectationSpec rejection.'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -19,14 +19,15 @@ describe('#toBeResolvedTo', function() {
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = Promise.reject('AsyncExpectationSpec error');
|
||||
actual = Promise.reject(new Error('AsyncExpectationSpec error'));
|
||||
|
||||
return matcher.compare(actual, '').then(function(result) {
|
||||
expect(result).toEqual(
|
||||
jasmine.objectContaining({
|
||||
pass: false,
|
||||
message:
|
||||
"Expected a promise to be resolved to '' but it was rejected."
|
||||
"Expected a promise to be resolved to '' but it was rejected " +
|
||||
'with Error: AsyncExpectationSpec error.'
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ getJasmineRequireObj().toBeResolved = function(j$) {
|
||||
* @example
|
||||
* return expectAsync(aPromise).toBeResolved();
|
||||
*/
|
||||
return function toBeResolved() {
|
||||
return function toBeResolved(matchersUtil) {
|
||||
return {
|
||||
compare: function(actual) {
|
||||
if (!j$.isPromiseLike(actual)) {
|
||||
@@ -21,8 +21,15 @@ getJasmineRequireObj().toBeResolved = function(j$) {
|
||||
function() {
|
||||
return { pass: true };
|
||||
},
|
||||
function() {
|
||||
return { pass: false };
|
||||
function(e) {
|
||||
return {
|
||||
pass: false,
|
||||
message:
|
||||
'Expected a promise to be resolved but it was ' +
|
||||
'rejected with ' +
|
||||
matchersUtil.pp(e) +
|
||||
'.'
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -45,10 +45,14 @@ getJasmineRequireObj().toBeResolvedTo = function(j$) {
|
||||
};
|
||||
}
|
||||
},
|
||||
function() {
|
||||
function(e) {
|
||||
return {
|
||||
pass: false,
|
||||
message: prefix(false) + ' but it was rejected.'
|
||||
message:
|
||||
prefix(false) +
|
||||
' but it was rejected with ' +
|
||||
matchersUtil.pp(e) +
|
||||
'.'
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user