Use toBeRejectedWith instead of toBeRejectedTo

This commit is contained in:
Gregg Van Hove
2018-10-22 11:18:56 -07:00
parent 06854fe435
commit fe042fdf82
2 changed files with 17 additions and 17 deletions

View File

@@ -108,7 +108,7 @@ describe('AsyncExpectation', function() {
}); });
}); });
describe('#toBeRejectedTo', function () { describe('#toBeRejectedWith', function () {
it('should return true if the promise is rejected to the expected value', function () { it('should return true if the promise is rejected to the expected value', function () {
jasmine.getEnv().requirePromises(); jasmine.getEnv().requirePromises();
@@ -120,9 +120,9 @@ describe('AsyncExpectation', function() {
addExpectationResult: addExpectationResult addExpectationResult: addExpectationResult
}); });
return expectation.toBeRejectedTo({error: 'PEBCAK'}).then(function () { return expectation.toBeRejectedWith({error: 'PEBCAK'}).then(function () {
expect(addExpectationResult).toHaveBeenCalledWith(true, { expect(addExpectationResult).toHaveBeenCalledWith(true, {
matcherName: 'toBeRejectedTo', matcherName: 'toBeRejectedWith',
passed: true, passed: true,
message: '', message: '',
error: undefined, error: undefined,
@@ -144,9 +144,9 @@ describe('AsyncExpectation', function() {
addExpectationResult: addExpectationResult addExpectationResult: addExpectationResult
}); });
return expectation.toBeRejectedTo('').then(function () { return expectation.toBeRejectedWith('').then(function () {
expect(addExpectationResult).toHaveBeenCalledWith(false, { expect(addExpectationResult).toHaveBeenCalledWith(false, {
matcherName: 'toBeRejectedTo', matcherName: 'toBeRejectedWith',
passed: false, passed: false,
message: "Expected a promise to be rejected to '' but it was resolved.", message: "Expected a promise to be rejected to '' but it was resolved.",
error: undefined, error: undefined,
@@ -167,9 +167,9 @@ describe('AsyncExpectation', function() {
addExpectationResult: addExpectationResult addExpectationResult: addExpectationResult
}); });
return expectation.toBeRejectedTo('Some Cool Thing').then(function () { return expectation.toBeRejectedWith('Some Cool Thing').then(function () {
expect(addExpectationResult).toHaveBeenCalledWith(false, { expect(addExpectationResult).toHaveBeenCalledWith(false, {
matcherName: 'toBeRejectedTo', matcherName: 'toBeRejectedWith',
passed: false, passed: false,
message: "Expected a promise to be rejected to 'Some Cool Thing' but it was rejected to 'A Bad Apple'.", message: "Expected a promise to be rejected to 'Some Cool Thing' but it was rejected to 'A Bad Apple'.",
error: undefined, error: undefined,
@@ -189,7 +189,7 @@ describe('AsyncExpectation', function() {
addExpectationResult: addExpectationResult addExpectationResult: addExpectationResult
}); });
return expectation.not.toBeRejectedTo(true).then(function () { return expectation.not.toBeRejectedWith(true).then(function () {
expect(addExpectationResult).toHaveBeenCalledWith(false, expect(addExpectationResult).toHaveBeenCalledWith(false,
jasmine.objectContaining({ jasmine.objectContaining({
passed: false, passed: false,
@@ -210,7 +210,7 @@ describe('AsyncExpectation', function() {
addExpectationResult: addExpectationResult addExpectationResult: addExpectationResult
}); });
return expectation.toBeRejectedTo('expected').then(function() { return expectation.toBeRejectedWith('expected').then(function() {
expect(addExpectationResult).toHaveBeenCalledWith(true, expect(addExpectationResult).toHaveBeenCalledWith(true,
jasmine.objectContaining({passed: true})); jasmine.objectContaining({passed: true}));
}); });
@@ -324,7 +324,7 @@ describe('AsyncExpectation', function() {
}); });
}); });
}); });
describe('#not', function() { describe('#not', function() {
it('converts a pass to a fail', function() { it('converts a pass to a fail', function() {
jasmine.getEnv().requirePromises(); jasmine.getEnv().requirePromises();
@@ -338,7 +338,7 @@ describe('AsyncExpectation', function() {
}); });
return expectation.not.toBeResolved().then(function() { return expectation.not.toBeResolved().then(function() {
expect(addExpectationResult).toHaveBeenCalledWith(false, expect(addExpectationResult).toHaveBeenCalledWith(false,
jasmine.objectContaining({ jasmine.objectContaining({
passed: false, passed: false,
message: 'Expected a promise not to be resolved.' message: 'Expected a promise not to be resolved.'
@@ -359,7 +359,7 @@ describe('AsyncExpectation', function() {
}); });
return expectation.not.toBeResolved().then(function() { return expectation.not.toBeResolved().then(function() {
expect(addExpectationResult).toHaveBeenCalledWith(true, expect(addExpectationResult).toHaveBeenCalledWith(true,
jasmine.objectContaining({ jasmine.objectContaining({
passed: true, passed: true,
message: '' message: ''

View File

@@ -23,7 +23,7 @@ getJasmineRequireObj().AsyncExpectation = function(j$) {
throw new Error('Expected expectAsync to be called with a promise.'); throw new Error('Expected expectAsync to be called with a promise.');
} }
['toBeResolved', 'toBeRejected', 'toBeResolvedTo', 'toBeRejectedTo'].forEach(wrapCompare.bind(this)); ['toBeResolved', 'toBeRejected', 'toBeResolvedTo', 'toBeRejectedWith'].forEach(wrapCompare.bind(this));
} }
function wrapCompare(name) { function wrapCompare(name) {
@@ -141,14 +141,14 @@ getJasmineRequireObj().AsyncExpectation = function(j$) {
* Expect a promise to be rejected to a value equal to the expected, using deep equality comparison. * Expect a promise to be rejected to a value equal to the expected, using deep equality comparison.
* @function * @function
* @async * @async
* @name async-matchers#toBeRejectedTo * @name async-matchers#toBeRejectedWith
* @param {Object} expected - Value that the promise is expected to reject to * @param {Object} expected - Value that the promise is expected to reject to
* @example * @example
* await expectAsync(aPromise).toBeRejectedTo({prop: 'value'}); * await expectAsync(aPromise).toBeRejectedWith({prop: 'value'});
* @example * @example
* return expectAsync(aPromise).toBeRejectedTo({prop: 'value'}); * return expectAsync(aPromise).toBeRejectedWith({prop: 'value'});
*/ */
AsyncExpectation.prototype.toBeRejectedTo = function(actualPromise, expectedValue) { AsyncExpectation.prototype.toBeRejectedWith = function(actualPromise, expectedValue) {
var self = this; var self = this;
function prefix(passed) { function prefix(passed) {