Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions packages/zone.js/lib/jasmine/jasmine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ Zone.__load_patch('jasmine', (global: any, Zone: ZoneType, api: _ZonePrivate) =>
function runInTestZone(
testBody: Function, applyThis: any, queueRunner: QueueRunner, done?: Function) {
const isClockInstalled = !!(jasmine as any)[symbol('clockInstalled')];
const testProxyZoneSpec = queueRunner.testProxyZoneSpec!;
const testProxyZone = queueRunner.testProxyZone!;
let lastDelegate;
if (isClockInstalled && enableAutoFakeAsyncWhenClockPatched) {
// auto run a fakeAsync
const fakeAsyncModule = (Zone as any)[Zone.__symbol__('fakeAsyncTest')];
Expand All @@ -203,7 +201,9 @@ Zone.__load_patch('jasmine', (global: any, Zone: ZoneType, api: _ZonePrivate) =>
}
}
if (done) {
return testProxyZone.run(testBody, applyThis, [done]);
// `done` should only be called once, otherwise Jasmine will log a
// deprecation warning which will eventually turn into an error.
return testProxyZone.run(testBody, applyThis, [callOnce(done)]);
} else {
return testProxyZone.run(testBody, applyThis);
}
Expand Down Expand Up @@ -343,4 +343,18 @@ Zone.__load_patch('jasmine', (global: any, Zone: ZoneType, api: _ZonePrivate) =>
};
return ZoneQueueRunner;
})(QueueRunner);

/** Wraps a function so it is only invoked once. */
function callOnce(fn: Function) {
let wasCalled = false;
let returnValue: unknown;

return function(this: unknown) {
if (!wasCalled) {
wasCalled = true;
returnValue = fn.apply(this, arguments);
}
return returnValue;
}
}
});