diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 9fd69021..41b88f0b 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -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) + + '.' }; } ); diff --git a/spec/core/AsyncExpectationSpec.js b/spec/core/AsyncExpectationSpec.js index 94e2438c..8772a9c8 100644 --- a/spec/core/AsyncExpectationSpec.js +++ b/spec/core/AsyncExpectationSpec.js @@ -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'." }) ); }); diff --git a/spec/core/matchers/async/toBeResolvedSpec.js b/spec/core/matchers/async/toBeResolvedSpec.js index 668b1bb3..b90a537d 100644 --- a/spec/core/matchers/async/toBeResolvedSpec.js +++ b/spec/core/matchers/async/toBeResolvedSpec.js @@ -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.' + }); }); }); diff --git a/spec/core/matchers/async/toBeResolvedToSpec.js b/spec/core/matchers/async/toBeResolvedToSpec.js index 459e93ac..734b780e 100644 --- a/spec/core/matchers/async/toBeResolvedToSpec.js +++ b/spec/core/matchers/async/toBeResolvedToSpec.js @@ -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.' }) ); }); diff --git a/src/core/matchers/async/toBeResolved.js b/src/core/matchers/async/toBeResolved.js index b9dda27a..0ef192be 100644 --- a/src/core/matchers/async/toBeResolved.js +++ b/src/core/matchers/async/toBeResolved.js @@ -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) + + '.' + }; } ); } diff --git a/src/core/matchers/async/toBeResolvedTo.js b/src/core/matchers/async/toBeResolvedTo.js index f95e7b10..235c3a22 100644 --- a/src/core/matchers/async/toBeResolvedTo.js +++ b/src/core/matchers/async/toBeResolvedTo.js @@ -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) + + '.' }; } );