From 55b3f97be0474b4a704e04aa2066c2545888f472 Mon Sep 17 00:00:00 2001 From: JiaLiPassion Date: Tue, 3 Mar 2020 11:00:21 +0900 Subject: [PATCH] fix(zone.js): `tickOptions`'s `processNewMacroTasksSynchronously` should default to true when flag omitted (#35814) Calling `tick(0, null)` defaults `processNewMacroTasksSynchronously` flag to `true`, however calling `tick(0, null, {})` defaults `processNewMacroTasksSynchronously` to `undefined`. This is undesirable behavior since unless the flag is set explicitly it should still default to `true`. PR Close #35814 --- packages/zone.js/lib/zone-spec/fake-async-test.ts | 5 +++-- .../zone.js/test/zone-spec/fake-async-test.spec.ts | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/zone.js/lib/zone-spec/fake-async-test.ts b/packages/zone.js/lib/zone-spec/fake-async-test.ts index 625b9a7763..661dc08e39 100644 --- a/packages/zone.js/lib/zone-spec/fake-async-test.ts +++ b/packages/zone.js/lib/zone-spec/fake-async-test.ts @@ -136,11 +136,12 @@ } } - tick(millis: number = 0, doTick?: (elapsed: number) => void, tickOptions: { + tick(millis: number = 0, doTick?: (elapsed: number) => void, tickOptions?: { processNewMacroTasksSynchronously: boolean - } = {processNewMacroTasksSynchronously: true}): void { + }): void { let finalTime = this._currentTime + millis; let lastCurrentTime = 0; + tickOptions = Object.assign({processNewMacroTasksSynchronously: true}, tickOptions); // we need to copy the schedulerQueue so nested timeout // will not be wrongly called in the current tick // https://github.com/angular/angular/issues/33799 diff --git a/packages/zone.js/test/zone-spec/fake-async-test.spec.ts b/packages/zone.js/test/zone-spec/fake-async-test.spec.ts index 6c7b82ed68..eae4658cb9 100644 --- a/packages/zone.js/test/zone-spec/fake-async-test.spec.ts +++ b/packages/zone.js/test/zone-spec/fake-async-test.spec.ts @@ -145,6 +145,20 @@ describe('FakeAsyncTestZoneSpec', () => { }); })); + it('should default to processNewMacroTasksSynchronously if providing other flags', () => { + function nestedTimer(callback: () => any): void { + setTimeout(() => setTimeout(() => callback())); + } + fakeAsyncTestZone.run(() => { + const callback = jasmine.createSpy('callback'); + nestedTimer(callback); + expect(callback).not.toHaveBeenCalled(); + testZoneSpec.tick(0, null, {}); + expect(callback).toHaveBeenCalled(); + }); + }); + + it('should not queue new macro task on tick with processNewMacroTasksSynchronously=false', () => { function nestedTimer(callback: () => any): void {