Removed support for custom promise libraries
All supported platforms now provide promises, so there's no longer a need for Jasmine to be able to create them via a user-provided library. Jasmine can still consume non-native promises but will always use the built-in Promise object to create promises. [#179078103]
This commit is contained in:
@@ -989,7 +989,6 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
|
||||
var self = this;
|
||||
var global = options.global || j$.getGlobal();
|
||||
var customPromise;
|
||||
|
||||
var totalSpecsDefined = 0;
|
||||
|
||||
@@ -1183,27 +1182,6 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
config.seed = configuration.seed;
|
||||
}
|
||||
|
||||
// Don't use hasOwnProperty to check for Promise existence because Promise
|
||||
// can be initialized to undefined, either explicitly or by using the
|
||||
// object returned from Env#configuration. In particular, Karma does this.
|
||||
if (configuration.Promise) {
|
||||
if (
|
||||
typeof configuration.Promise.resolve === 'function' &&
|
||||
typeof configuration.Promise.reject === 'function'
|
||||
) {
|
||||
customPromise = configuration.Promise;
|
||||
self.deprecated(
|
||||
'The `Promise` config property is deprecated. Future versions ' +
|
||||
'of Jasmine will create native promises even if the `Promise` ' +
|
||||
'config property is set. Please remove it.'
|
||||
);
|
||||
} else {
|
||||
throw new Error(
|
||||
'Custom promise library missing `resolve`/`reject` functions'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (configuration.hasOwnProperty('verboseDeprecations')) {
|
||||
config.verboseDeprecations = configuration.verboseDeprecations;
|
||||
deprecator.verboseDeprecations(config.verboseDeprecations);
|
||||
@@ -1696,25 +1674,15 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
var jasmineTimer = new j$.Timer();
|
||||
jasmineTimer.start();
|
||||
|
||||
var Promise = customPromise || global.Promise;
|
||||
|
||||
if (Promise) {
|
||||
return new Promise(function(resolve) {
|
||||
runAll(function() {
|
||||
if (onComplete) {
|
||||
onComplete();
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return new Promise(function(resolve) {
|
||||
runAll(function() {
|
||||
if (onComplete) {
|
||||
onComplete();
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function runAll(done) {
|
||||
/**
|
||||
@@ -1830,9 +1798,6 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
function getPromise() {
|
||||
return customPromise || global.Promise;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -8229,13 +8194,7 @@ getJasmineRequireObj().Spy = function(j$) {
|
||||
* @class Spy
|
||||
* @hideconstructor
|
||||
*/
|
||||
function Spy(
|
||||
name,
|
||||
originalFn,
|
||||
customStrategies,
|
||||
defaultStrategyFn,
|
||||
getPromise
|
||||
) {
|
||||
function Spy(name, originalFn, customStrategies, defaultStrategyFn) {
|
||||
var numArgs = typeof originalFn === 'function' ? originalFn.length : 0,
|
||||
wrapper = makeFunc(numArgs, function(context, args, invokeNew) {
|
||||
return spy(context, args, invokeNew);
|
||||
@@ -8246,8 +8205,7 @@ getJasmineRequireObj().Spy = function(j$) {
|
||||
getSpy: function() {
|
||||
return wrapper;
|
||||
},
|
||||
customStrategies: customStrategies,
|
||||
getPromise: getPromise
|
||||
customStrategies: customStrategies
|
||||
}),
|
||||
callTracker = new j$.CallTracker(),
|
||||
spy = function(context, args, invokeNew) {
|
||||
@@ -8430,7 +8388,7 @@ getJasmineRequireObj().Spy = function(j$) {
|
||||
};
|
||||
|
||||
getJasmineRequireObj().SpyFactory = function(j$) {
|
||||
function SpyFactory(getCustomStrategies, getDefaultStrategyFn, getPromise) {
|
||||
function SpyFactory(getCustomStrategies, getDefaultStrategyFn) {
|
||||
var self = this;
|
||||
|
||||
this.createSpy = function(name, originalFn) {
|
||||
@@ -8438,8 +8396,7 @@ getJasmineRequireObj().SpyFactory = function(j$) {
|
||||
name,
|
||||
originalFn,
|
||||
getCustomStrategies(),
|
||||
getDefaultStrategyFn(),
|
||||
getPromise
|
||||
getDefaultStrategyFn()
|
||||
);
|
||||
};
|
||||
|
||||
@@ -8791,24 +8748,6 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
||||
}
|
||||
}
|
||||
|
||||
var getPromise =
|
||||
typeof options.getPromise === 'function'
|
||||
? options.getPromise
|
||||
: function() {};
|
||||
|
||||
var requirePromise = function(name) {
|
||||
var Promise = getPromise();
|
||||
|
||||
if (!Promise) {
|
||||
throw new Error(
|
||||
name +
|
||||
' requires global Promise, or `Promise` configured with `jasmine.getEnv().configure()`'
|
||||
);
|
||||
}
|
||||
|
||||
return Promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Tell the spy to return a promise resolving to the specified value when invoked.
|
||||
* @name SpyStrategy#resolveTo
|
||||
@@ -8817,7 +8756,6 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
||||
* @param {*} value The value to return.
|
||||
*/
|
||||
this.resolveTo = function(value) {
|
||||
var Promise = requirePromise('resolveTo');
|
||||
self.plan = function() {
|
||||
return Promise.resolve(value);
|
||||
};
|
||||
@@ -8832,8 +8770,6 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
||||
* @param {*} value The value to return.
|
||||
*/
|
||||
this.rejectWith = function(value) {
|
||||
var Promise = requirePromise('rejectWith');
|
||||
|
||||
self.plan = function() {
|
||||
return Promise.reject(value);
|
||||
};
|
||||
|
||||
@@ -137,37 +137,6 @@ describe('Env', function() {
|
||||
);
|
||||
});
|
||||
|
||||
describe('promise library', function() {
|
||||
it('can be configured without a custom library', function() {
|
||||
env.configure({});
|
||||
env.configure({ Promise: undefined });
|
||||
});
|
||||
|
||||
it('can be configured with a custom library', function() {
|
||||
spyOn(env, 'deprecated');
|
||||
var myLibrary = {
|
||||
resolve: jasmine.createSpy(),
|
||||
reject: jasmine.createSpy()
|
||||
};
|
||||
env.configure({ Promise: myLibrary });
|
||||
expect(env.deprecated).toHaveBeenCalledWith(
|
||||
'The `Promise` config property is deprecated. Future versions of ' +
|
||||
'Jasmine will create native promises even if the `Promise` config ' +
|
||||
'property is set. Please remove it.'
|
||||
);
|
||||
});
|
||||
|
||||
it('cannot be configured with an invalid promise library', function() {
|
||||
var myLibrary = {};
|
||||
|
||||
expect(function() {
|
||||
env.configure({ Promise: myLibrary });
|
||||
}).toThrowError(
|
||||
'Custom promise library missing `resolve`/`reject` functions'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('defaults to multiple failures for specs', function() {
|
||||
spyOn(jasmineUnderTest, 'Spec').and.callThrough();
|
||||
env.it('bar', function() {});
|
||||
|
||||
@@ -248,7 +248,7 @@ describe('Spies', function() {
|
||||
});
|
||||
|
||||
describe('any promise-based strategy', function() {
|
||||
it('works with global Promise library when available', function(done) {
|
||||
it('works with global Promise library', function(done) {
|
||||
var spy = env.createSpy('foo').and.resolveTo(42);
|
||||
spy()
|
||||
.then(function(result) {
|
||||
@@ -257,20 +257,6 @@ describe('Spies', function() {
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('works with a custom Promise library', function() {
|
||||
var customPromise = {
|
||||
resolve: jasmine.createSpy(),
|
||||
reject: jasmine.createSpy()
|
||||
};
|
||||
customPromise.resolve.and.returnValue('resolved');
|
||||
spyOn(env, 'deprecated');
|
||||
env.configure({ Promise: customPromise });
|
||||
|
||||
var spy = env.createSpy('foo').and.resolveTo(42);
|
||||
expect(spy()).toEqual('resolved');
|
||||
expect(customPromise.resolve).toHaveBeenCalledWith(42);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when withArgs is used without a base strategy', function() {
|
||||
|
||||
@@ -131,12 +131,8 @@ describe('SpyStrategy', function() {
|
||||
describe('#resolveTo', function() {
|
||||
it('allows a resolved promise to be returned', function(done) {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
getPromise = function() {
|
||||
return Promise;
|
||||
},
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||
fn: originalFn,
|
||||
getPromise: getPromise
|
||||
fn: originalFn
|
||||
});
|
||||
|
||||
spyStrategy.resolveTo(37);
|
||||
@@ -151,12 +147,8 @@ describe('SpyStrategy', function() {
|
||||
|
||||
it('allows an empty resolved promise to be returned', function(done) {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
getPromise = function() {
|
||||
return Promise;
|
||||
},
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||
fn: originalFn,
|
||||
getPromise: getPromise
|
||||
fn: originalFn
|
||||
});
|
||||
|
||||
spyStrategy.resolveTo();
|
||||
@@ -168,28 +160,13 @@ describe('SpyStrategy', function() {
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('fails if promises are not available', function() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||
|
||||
expect(function() {
|
||||
spyStrategy.resolveTo(37);
|
||||
}).toThrowError(
|
||||
'resolveTo requires global Promise, or `Promise` configured with `jasmine.getEnv().configure()`'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#rejectWith', function() {
|
||||
it('allows a rejected promise to be returned', function(done) {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
getPromise = function() {
|
||||
return Promise;
|
||||
},
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||
fn: originalFn,
|
||||
getPromise: getPromise
|
||||
fn: originalFn
|
||||
});
|
||||
|
||||
spyStrategy.rejectWith(new Error('oops'));
|
||||
@@ -205,12 +182,8 @@ describe('SpyStrategy', function() {
|
||||
|
||||
it('allows an empty rejected promise to be returned', function(done) {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
getPromise = function() {
|
||||
return Promise;
|
||||
},
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||
fn: originalFn,
|
||||
getPromise: getPromise
|
||||
fn: originalFn
|
||||
});
|
||||
|
||||
spyStrategy.rejectWith();
|
||||
@@ -226,12 +199,8 @@ describe('SpyStrategy', function() {
|
||||
|
||||
it('allows a non-Error to be rejected', function(done) {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
getPromise = function() {
|
||||
return Promise;
|
||||
},
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({
|
||||
fn: originalFn,
|
||||
getPromise: getPromise
|
||||
fn: originalFn
|
||||
});
|
||||
|
||||
spyStrategy.rejectWith('oops');
|
||||
@@ -244,17 +213,6 @@ describe('SpyStrategy', function() {
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('fails if promises are not available', function() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||
|
||||
expect(function() {
|
||||
spyStrategy.rejectWith(new Error('oops'));
|
||||
}).toThrowError(
|
||||
'rejectWith requires global Promise, or `Promise` configured with `jasmine.getEnv().configure()`'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('allows a custom strategy to be used', function() {
|
||||
|
||||
@@ -12,7 +12,6 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
|
||||
var self = this;
|
||||
var global = options.global || j$.getGlobal();
|
||||
var customPromise;
|
||||
|
||||
var totalSpecsDefined = 0;
|
||||
|
||||
@@ -206,27 +205,6 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
config.seed = configuration.seed;
|
||||
}
|
||||
|
||||
// Don't use hasOwnProperty to check for Promise existence because Promise
|
||||
// can be initialized to undefined, either explicitly or by using the
|
||||
// object returned from Env#configuration. In particular, Karma does this.
|
||||
if (configuration.Promise) {
|
||||
if (
|
||||
typeof configuration.Promise.resolve === 'function' &&
|
||||
typeof configuration.Promise.reject === 'function'
|
||||
) {
|
||||
customPromise = configuration.Promise;
|
||||
self.deprecated(
|
||||
'The `Promise` config property is deprecated. Future versions ' +
|
||||
'of Jasmine will create native promises even if the `Promise` ' +
|
||||
'config property is set. Please remove it.'
|
||||
);
|
||||
} else {
|
||||
throw new Error(
|
||||
'Custom promise library missing `resolve`/`reject` functions'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (configuration.hasOwnProperty('verboseDeprecations')) {
|
||||
config.verboseDeprecations = configuration.verboseDeprecations;
|
||||
deprecator.verboseDeprecations(config.verboseDeprecations);
|
||||
@@ -719,25 +697,15 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
var jasmineTimer = new j$.Timer();
|
||||
jasmineTimer.start();
|
||||
|
||||
var Promise = customPromise || global.Promise;
|
||||
|
||||
if (Promise) {
|
||||
return new Promise(function(resolve) {
|
||||
runAll(function() {
|
||||
if (onComplete) {
|
||||
onComplete();
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return new Promise(function(resolve) {
|
||||
runAll(function() {
|
||||
if (onComplete) {
|
||||
onComplete();
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function runAll(done) {
|
||||
/**
|
||||
@@ -853,9 +821,6 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
function getPromise() {
|
||||
return customPromise || global.Promise;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -19,13 +19,7 @@ getJasmineRequireObj().Spy = function(j$) {
|
||||
* @class Spy
|
||||
* @hideconstructor
|
||||
*/
|
||||
function Spy(
|
||||
name,
|
||||
originalFn,
|
||||
customStrategies,
|
||||
defaultStrategyFn,
|
||||
getPromise
|
||||
) {
|
||||
function Spy(name, originalFn, customStrategies, defaultStrategyFn) {
|
||||
var numArgs = typeof originalFn === 'function' ? originalFn.length : 0,
|
||||
wrapper = makeFunc(numArgs, function(context, args, invokeNew) {
|
||||
return spy(context, args, invokeNew);
|
||||
@@ -36,8 +30,7 @@ getJasmineRequireObj().Spy = function(j$) {
|
||||
getSpy: function() {
|
||||
return wrapper;
|
||||
},
|
||||
customStrategies: customStrategies,
|
||||
getPromise: getPromise
|
||||
customStrategies: customStrategies
|
||||
}),
|
||||
callTracker = new j$.CallTracker(),
|
||||
spy = function(context, args, invokeNew) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
getJasmineRequireObj().SpyFactory = function(j$) {
|
||||
function SpyFactory(getCustomStrategies, getDefaultStrategyFn, getPromise) {
|
||||
function SpyFactory(getCustomStrategies, getDefaultStrategyFn) {
|
||||
var self = this;
|
||||
|
||||
this.createSpy = function(name, originalFn) {
|
||||
@@ -7,8 +7,7 @@ getJasmineRequireObj().SpyFactory = function(j$) {
|
||||
name,
|
||||
originalFn,
|
||||
getCustomStrategies(),
|
||||
getDefaultStrategyFn(),
|
||||
getPromise
|
||||
getDefaultStrategyFn()
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -27,24 +27,6 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
||||
}
|
||||
}
|
||||
|
||||
var getPromise =
|
||||
typeof options.getPromise === 'function'
|
||||
? options.getPromise
|
||||
: function() {};
|
||||
|
||||
var requirePromise = function(name) {
|
||||
var Promise = getPromise();
|
||||
|
||||
if (!Promise) {
|
||||
throw new Error(
|
||||
name +
|
||||
' requires global Promise, or `Promise` configured with `jasmine.getEnv().configure()`'
|
||||
);
|
||||
}
|
||||
|
||||
return Promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Tell the spy to return a promise resolving to the specified value when invoked.
|
||||
* @name SpyStrategy#resolveTo
|
||||
@@ -53,7 +35,6 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
||||
* @param {*} value The value to return.
|
||||
*/
|
||||
this.resolveTo = function(value) {
|
||||
var Promise = requirePromise('resolveTo');
|
||||
self.plan = function() {
|
||||
return Promise.resolve(value);
|
||||
};
|
||||
@@ -68,8 +49,6 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
||||
* @param {*} value The value to return.
|
||||
*/
|
||||
this.rejectWith = function(value) {
|
||||
var Promise = requirePromise('rejectWith');
|
||||
|
||||
self.plan = function() {
|
||||
return Promise.reject(value);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user