Promise-based strategies are now named resolveWith and rejectWith
This commit is contained in:
@@ -175,7 +175,7 @@ describe('Spies', function () {
|
|||||||
it('works with global Promise library when available', function(done) {
|
it('works with global Promise library when available', function(done) {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
var spy = env.createSpy('foo').and.resolveValue(42);
|
var spy = env.createSpy('foo').and.resolveWith(42);
|
||||||
spy().then(function(result) {
|
spy().then(function(result) {
|
||||||
expect(result).toEqual(42);
|
expect(result).toEqual(42);
|
||||||
done();
|
done();
|
||||||
@@ -187,7 +187,7 @@ describe('Spies', function () {
|
|||||||
customPromise.resolve.and.returnValue('resolved');
|
customPromise.resolve.and.returnValue('resolved');
|
||||||
env.configure({ Promise: customPromise });
|
env.configure({ Promise: customPromise });
|
||||||
|
|
||||||
var spy = env.createSpy('foo').and.resolveValue(42);
|
var spy = env.createSpy('foo').and.resolveWith(42);
|
||||||
expect(spy()).toEqual('resolved');
|
expect(spy()).toEqual('resolved');
|
||||||
expect(customPromise.resolve).toHaveBeenCalledWith(42);
|
expect(customPromise.resolve).toHaveBeenCalledWith(42);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ describe("SpyStrategy", function() {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#resolveValue", function() {
|
describe("#resolveWith", function() {
|
||||||
it("allows a resolved promise to be returned", function(done) {
|
it("allows a resolved promise to be returned", function(done) {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ describe("SpyStrategy", function() {
|
|||||||
getPromise = function() { return Promise; },
|
getPromise = function() { return Promise; },
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn, getPromise: getPromise});
|
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn, getPromise: getPromise});
|
||||||
|
|
||||||
spyStrategy.resolveValue(37);
|
spyStrategy.resolveWith(37);
|
||||||
spyStrategy.exec().then(function (returnValue) {
|
spyStrategy.exec().then(function (returnValue) {
|
||||||
expect(returnValue).toEqual(37);
|
expect(returnValue).toEqual(37);
|
||||||
done();
|
done();
|
||||||
@@ -130,12 +130,12 @@ describe("SpyStrategy", function() {
|
|||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn});
|
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn});
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
spyStrategy.resolveValue(37);
|
spyStrategy.resolveWith(37);
|
||||||
}).toThrowError('resolveValue requires global Promise, or `Promise` configured with `jasmine.getEnv().configure()`');
|
}).toThrowError('resolveWith requires global Promise, or `Promise` configured with `jasmine.getEnv().configure()`');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#rejectValue", function() {
|
describe("#rejectWith", function() {
|
||||||
it("allows a rejected promise to be returned", function(done) {
|
it("allows a rejected promise to be returned", function(done) {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ describe("SpyStrategy", function() {
|
|||||||
getPromise = function() { return Promise; },
|
getPromise = function() { return Promise; },
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn, getPromise: getPromise});
|
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn, getPromise: getPromise});
|
||||||
|
|
||||||
spyStrategy.rejectValue(new Error('oops'));
|
spyStrategy.rejectWith(new Error('oops'));
|
||||||
spyStrategy.exec().then(done.fail).catch(function (error) {
|
spyStrategy.exec().then(done.fail).catch(function (error) {
|
||||||
expect(error).toEqual(new Error('oops'));
|
expect(error).toEqual(new Error('oops'));
|
||||||
done();
|
done();
|
||||||
@@ -157,7 +157,7 @@ describe("SpyStrategy", function() {
|
|||||||
getPromise = function() { return Promise; },
|
getPromise = function() { return Promise; },
|
||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn, getPromise: getPromise});
|
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn, getPromise: getPromise});
|
||||||
|
|
||||||
spyStrategy.rejectValue('oops');
|
spyStrategy.rejectWith('oops');
|
||||||
spyStrategy.exec().then(done.fail).catch(function (error) {
|
spyStrategy.exec().then(done.fail).catch(function (error) {
|
||||||
expect(error).toEqual(new Error('oops'));
|
expect(error).toEqual(new Error('oops'));
|
||||||
done();
|
done();
|
||||||
@@ -169,8 +169,8 @@ describe("SpyStrategy", function() {
|
|||||||
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn});
|
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn});
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
spyStrategy.rejectValue(new Error('oops'));
|
spyStrategy.rejectWith(new Error('oops'));
|
||||||
}).toThrowError('rejectValue requires global Promise, or `Promise` configured with `jasmine.getEnv().configure()`');
|
}).toThrowError('rejectWith requires global Promise, or `Promise` configured with `jasmine.getEnv().configure()`');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell the spy to return a promise resolving to the specified value when invoked.
|
* Tell the spy to return a promise resolving to the specified value when invoked.
|
||||||
* @name SpyStrategy#resolveValue
|
* @name SpyStrategy#resolveWith
|
||||||
* @function
|
* @function
|
||||||
* @param {*} value The value to return.
|
* @param {*} value The value to return.
|
||||||
*/
|
*/
|
||||||
this.resolveValue = function(value) {
|
this.resolveWith = function(value) {
|
||||||
var Promise = requirePromise('resolveValue');
|
var Promise = requirePromise('resolveWith');
|
||||||
self.plan = function() {
|
self.plan = function() {
|
||||||
return Promise.resolve(value);
|
return Promise.resolve(value);
|
||||||
};
|
};
|
||||||
@@ -54,12 +54,12 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell the spy to return a promise rejecting with the specified value when invoked.
|
* Tell the spy to return a promise rejecting with the specified value when invoked.
|
||||||
* @name SpyStrategy#rejectValue
|
* @name SpyStrategy#rejectWith
|
||||||
* @function
|
* @function
|
||||||
* @param {*} value The value to return.
|
* @param {*} value The value to return.
|
||||||
*/
|
*/
|
||||||
this.rejectValue = function(value) {
|
this.rejectWith = function(value) {
|
||||||
var Promise = requirePromise('rejectValue');
|
var Promise = requirePromise('rejectWith');
|
||||||
var error = (value instanceof Error) ? value : new Error(value);
|
var error = (value instanceof Error) ? value : new Error(value);
|
||||||
|
|
||||||
self.plan = function() {
|
self.plan = function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user