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:
@@ -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