Skip to content

Commit c4c340a

Browse files
vikermanmatsko
authored andcommitted
fix(zone.js): fix zone for Jasmine 3.3. (#31497)
If zonejs is sent undefined callbacks it proceeds to attempt to call them, then fails, catches it own fail, rewrites the stack to hide the mistake, and reports a TypeError with a callstack unrelated to inputs. Throw early if the callback is undefined (as can happen if JS or any-ified TS calls zone invokeTask). Check for undefined onCommplete callback to zonejs jasmine wrapper. PR Close #31497
1 parent 32aa18b commit c4c340a

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

packages/zone.js/lib/jasmine/jasmine.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,14 @@
204204
(jasmine as any).QueueRunner = (function(_super) {
205205
__extends(ZoneQueueRunner, _super);
206206
function ZoneQueueRunner(attrs: QueueRunnerAttrs) {
207-
attrs.onComplete = (fn => () => {
208-
// All functions are done, clear the test zone.
209-
this.testProxyZone = null;
210-
this.testProxyZoneSpec = null;
211-
ambientZone.scheduleMicroTask('jasmine.onComplete', fn);
212-
})(attrs.onComplete);
207+
if (attrs.onComplete) {
208+
attrs.onComplete = (fn => () => {
209+
// All functions are done, clear the test zone.
210+
this.testProxyZone = null;
211+
this.testProxyZoneSpec = null;
212+
ambientZone.scheduleMicroTask('jasmine.onComplete', fn);
213+
})(attrs.onComplete);
214+
}
213215

214216
const nativeSetTimeout = _global[Zone.__symbol__('setTimeout')];
215217
const nativeClearTimeout = _global[Zone.__symbol__('clearTimeout')];

packages/zone.js/lib/zone.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,9 @@ const Zone: ZoneType = (function(global: any) {
12171217
this.data = options;
12181218
this.scheduleFn = scheduleFn;
12191219
this.cancelFn = cancelFn;
1220+
if (!callback) {
1221+
throw new Error('callback is not defined');
1222+
}
12201223
this.callback = callback;
12211224
const self = this;
12221225
// TODO: @JiaLiPassion options should have interface

0 commit comments

Comments
 (0)