Warn if a runable both takes a callback and returns a promise
This commit is contained in:
@@ -123,7 +123,8 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
}),
|
||||
errored = false,
|
||||
queueableFn = self.queueableFns[iterativeIndex],
|
||||
timeoutId;
|
||||
timeoutId,
|
||||
maybeThenable;
|
||||
|
||||
next.fail = function nextFail() {
|
||||
self.fail.apply(null, arguments);
|
||||
@@ -151,7 +152,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
|
||||
try {
|
||||
if (queueableFn.fn.length === 0) {
|
||||
var maybeThenable = queueableFn.fn.call(self.userContext);
|
||||
maybeThenable = queueableFn.fn.call(self.userContext);
|
||||
|
||||
if (maybeThenable && j$.isFunction_(maybeThenable.then)) {
|
||||
maybeThenable.then(next, onPromiseRejection);
|
||||
@@ -159,7 +160,8 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
return { completedSynchronously: false };
|
||||
}
|
||||
} else {
|
||||
queueableFn.fn.call(self.userContext, next);
|
||||
maybeThenable = queueableFn.fn.call(self.userContext, next);
|
||||
this.diagnoseConflictingAsync_(queueableFn.fn, maybeThenable);
|
||||
completedSynchronously = false;
|
||||
return { completedSynchronously: false };
|
||||
}
|
||||
@@ -212,5 +214,24 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
});
|
||||
};
|
||||
|
||||
QueueRunner.prototype.diagnoseConflictingAsync_ = function(fn, retval) {
|
||||
if (retval && j$.isFunction_(retval.then)) {
|
||||
// Issue a warning that matches the user's code
|
||||
if (j$.isAsyncFunction_(fn)) {
|
||||
this.deprecated('An asynchronous before/it/after ' +
|
||||
'function was defined with the async keyword but also took a ' +
|
||||
'done callback. This is not supported and will stop working in' +
|
||||
' the future. Either remove the done callback (recommended) or ' +
|
||||
'remove the async keyword.');
|
||||
} else {
|
||||
this.deprecated('An asynchronous before/it/after ' +
|
||||
'function took a done callback but also returned a promise. ' +
|
||||
'This is not supported and will stop working in the future. ' +
|
||||
'Either remove the done callback (recommended) or change the ' +
|
||||
'function to not return a promise.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return QueueRunner;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user