Fail specs that try to combine two forms of async

This commit is contained in:
Steve Gravrock
2020-09-17 14:47:25 -07:00
parent 235efe52f1
commit c2b558a2da
3 changed files with 16 additions and 21 deletions

View File

@@ -7449,18 +7449,16 @@ getJasmineRequireObj().QueueRunner = function(j$) {
if (retval && j$.isFunction_(retval.then)) { if (retval && j$.isFunction_(retval.then)) {
// Issue a warning that matches the user's code // Issue a warning that matches the user's code
if (j$.isAsyncFunction_(fn)) { if (j$.isAsyncFunction_(fn)) {
this.deprecated( this.onException(
'An asynchronous before/it/after ' + 'An asynchronous before/it/after ' +
'function was defined with the async keyword but also took a ' + 'function was defined with the async keyword but also took a ' +
'done callback. This is not supported and will stop working in' + 'done callback. Either remove the done callback (recommended) or ' +
' the future. Either remove the done callback (recommended) or ' +
'remove the async keyword.' 'remove the async keyword.'
); );
} else { } else {
this.deprecated( this.onException(
'An asynchronous before/it/after ' + 'An asynchronous before/it/after ' +
'function took a done callback but also returned a promise. ' + '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 ' + 'Either remove the done callback (recommended) or change the ' +
'function to not return a promise.' 'function to not return a promise.'
); );

View File

@@ -513,46 +513,45 @@ describe('QueueRunner', function() {
expect(queueableFn2.fn).toHaveBeenCalled(); expect(queueableFn2.fn).toHaveBeenCalled();
}); });
it('issues a deprecation if the function also takes a parameter', function() { it('issues an error if the function also takes a parameter', function() {
var queueableFn = { var queueableFn = {
fn: function(done) { fn: function(done) {
return new StubPromise(); return new StubPromise();
} }
}, },
deprecated = jasmine.createSpy('deprecated'), onException = jasmine.createSpy('onException'),
queueRunner = new jasmineUnderTest.QueueRunner({ queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn], queueableFns: [queueableFn],
deprecated: deprecated onException: onException
}), }),
env = jasmineUnderTest.getEnv(); env = jasmineUnderTest.getEnv();
queueRunner.execute(); queueRunner.execute();
expect(deprecated).toHaveBeenCalledWith( expect(onException).toHaveBeenCalledWith(
'An asynchronous ' + 'An asynchronous ' +
'before/it/after function took a done callback but also returned a ' + 'before/it/after function took a done callback but also returned a ' +
'promise. This is not supported and will stop working in the future. ' + 'promise. ' +
'Either remove the done callback (recommended) or change the function ' + 'Either remove the done callback (recommended) or change the function ' +
'to not return a promise.' 'to not return a promise.'
); );
}); });
it('issues a more specific deprecation if the function is `async`', function() { it('issues a more specific error if the function is `async`', function() {
jasmine.getEnv().requireAsyncAwait(); jasmine.getEnv().requireAsyncAwait();
eval('var fn = async function(done){};'); eval('var fn = async function(done){};');
var deprecated = jasmine.createSpy('deprecated'), var onException = jasmine.createSpy('onException'),
queueRunner = new jasmineUnderTest.QueueRunner({ queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [{ fn: fn }], queueableFns: [{ fn: fn }],
deprecated: deprecated onException: onException
}); });
queueRunner.execute(); queueRunner.execute();
expect(deprecated).toHaveBeenCalledWith( expect(onException).toHaveBeenCalledWith(
'An asynchronous ' + 'An asynchronous ' +
'before/it/after function was defined with the async keyword but ' + 'before/it/after function was defined with the async keyword but ' +
'also took a done callback. This is not supported and will stop ' + 'also took a done callback. Either remove the done callback ' +
'working in the future. Either remove the done callback ' +
'(recommended) or remove the async keyword.' '(recommended) or remove the async keyword.'
); );
}); });

View File

@@ -218,18 +218,16 @@ getJasmineRequireObj().QueueRunner = function(j$) {
if (retval && j$.isFunction_(retval.then)) { if (retval && j$.isFunction_(retval.then)) {
// Issue a warning that matches the user's code // Issue a warning that matches the user's code
if (j$.isAsyncFunction_(fn)) { if (j$.isAsyncFunction_(fn)) {
this.deprecated( this.onException(
'An asynchronous before/it/after ' + 'An asynchronous before/it/after ' +
'function was defined with the async keyword but also took a ' + 'function was defined with the async keyword but also took a ' +
'done callback. This is not supported and will stop working in' + 'done callback. Either remove the done callback (recommended) or ' +
' the future. Either remove the done callback (recommended) or ' +
'remove the async keyword.' 'remove the async keyword.'
); );
} else { } else {
this.deprecated( this.onException(
'An asynchronous before/it/after ' + 'An asynchronous before/it/after ' +
'function took a done callback but also returned a promise. ' + '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 ' + 'Either remove the done callback (recommended) or change the ' +
'function to not return a promise.' 'function to not return a promise.'
); );