From f84d7dde872bbb44fa7a482565c0046a06d7f55c Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Mon, 22 Apr 2024 12:31:30 -0700 Subject: [PATCH] test(core): Wait for zone stability before test completion (#55468) Need to wait for microtaskEmty to emit or test will leak into others. PR Close #55468 --- packages/core/test/zone/ng_zone_spec.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/test/zone/ng_zone_spec.ts b/packages/core/test/zone/ng_zone_spec.ts index effa39e6b4df9..ff426b8b57ad5 100644 --- a/packages/core/test/zone/ng_zone_spec.ts +++ b/packages/core/test/zone/ng_zone_spec.ts @@ -9,6 +9,7 @@ import {EventEmitter, NgZone} from '@angular/core'; import {fakeAsync, flushMicrotasks, inject, waitForAsync} from '@angular/core/testing'; import {Log} from '@angular/core/testing/src/testing_internal'; +import {firstValueFrom} from 'rxjs'; import {scheduleCallbackWithRafRace as scheduler} from '../../src/util/callback_scheduler'; import {global} from '../../src/util/global'; @@ -1193,10 +1194,13 @@ function commonTests() { }); }); - it('does not throw when apply args array has `undefined`', () => { + it('does not throw when apply args array has `undefined`', async () => { expect(() => { coalesceZone.run(function(this: any, arg: any) {}, undefined, [undefined]); }).not.toThrow(); + // wait for the zone to stabilize after the task above. Needed to prevent this from leaking + // into a follow-up test + await firstValueFrom(coalesceZone.onMicrotaskEmpty); }); }); });