From 30a24b6bf5fd1d34d467ccf9a617fb431d4a0d4c Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Wed, 21 Apr 2021 11:44:47 +0200 Subject: [PATCH] test: use `global` util instead of `global` property. (#41739) `global` property is not available in the browser, previously this was polyfilled through core-js. (cherry picked from commit 827cf41386dcd7e496e107d6b32c54281bc935f1) PR Close #41739 --- .../core/test/acceptance/component_spec.ts | 3 ++- packages/core/test/zone/ng_zone_spec.ts | 21 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/core/test/acceptance/component_spec.ts b/packages/core/test/acceptance/component_spec.ts index 41c8208b78..31994aadac 100644 --- a/packages/core/test/acceptance/component_spec.ts +++ b/packages/core/test/acceptance/component_spec.ts @@ -14,6 +14,7 @@ import {expect} from '@angular/platform-browser/testing/src/matchers'; import {ivyEnabled, onlyInIvy} from '@angular/private/testing'; import {domRendererFactory3} from '../../src/render3/interfaces/renderer'; +import {global} from '../../src/util/global'; describe('component', () => { @@ -304,7 +305,7 @@ describe('component', () => { }); describe('with ngDevMode', () => { - const _global: {ngDevMode: any} = global as any; + const _global: {ngDevMode: any} = global; let saveNgDevMode!: typeof ngDevMode; beforeEach(() => saveNgDevMode = ngDevMode); afterEach(() => _global.ngDevMode = saveNgDevMode); diff --git a/packages/core/test/zone/ng_zone_spec.ts b/packages/core/test/zone/ng_zone_spec.ts index dd9b6cc5ad..2ab461b0b1 100644 --- a/packages/core/test/zone/ng_zone_spec.ts +++ b/packages/core/test/zone/ng_zone_spec.ts @@ -11,6 +11,7 @@ import {fakeAsync, flushMicrotasks, waitForAsync} from '@angular/core/testing'; import {AsyncTestCompleter, beforeEach, describe, expect, inject, it, Log, xit} from '@angular/core/testing/src/testing_internal'; import {browserDetection} from '@angular/platform-browser/testing/src/browser_util'; +import {global} from '../../src/util/global'; import {scheduleMicroTask} from '../../src/util/microtask'; import {getNativeRequestAnimationFrame} from '../../src/util/raf'; import {NoopNgZone} from '../../src/zone/ng_zone'; @@ -982,10 +983,10 @@ function commonTests() { describe('shouldCoalesceEventChangeDetection = true, shouldCoalesceRunChangeDetection = false', () => { let nativeRequestAnimationFrame: (fn: FrameRequestCallback) => void; - let nativeSetTimeout: any = (global as any)[Zone.__symbol__('setTimeout')]; - if (!(global as any).requestAnimationFrame) { + let nativeSetTimeout: any = global[Zone.__symbol__('setTimeout')]; + if (!global.requestAnimationFrame) { nativeRequestAnimationFrame = function(fn: Function) { - (global as any)[Zone.__symbol__('setTimeout')](fn, 16); + global[Zone.__symbol__('setTimeout')](fn, 16); }; } else { nativeRequestAnimationFrame = getNativeRequestAnimationFrame().nativeRequestAnimationFrame; @@ -996,7 +997,7 @@ function commonTests() { beforeEach(() => { patchedImmediate = setImmediate; - (global as any).setImmediate = (global as any)[Zone.__symbol__('setImmediate')]; + global.setImmediate = global[Zone.__symbol__('setImmediate')]; coalesceZone = new NgZone({shouldCoalesceEventChangeDetection: true}); logs = []; coalesceZone.onMicrotaskEmpty.subscribe(() => { @@ -1005,7 +1006,7 @@ function commonTests() { }); afterEach(() => { - (global as any).setImmediate = patchedImmediate; + global.setImmediate = patchedImmediate; }); it('should run in requestAnimationFrame async', (done: DoneFn) => { @@ -1121,10 +1122,10 @@ function commonTests() { describe('shouldCoalesceRunChangeDetection = true', () => { let nativeRequestAnimationFrame: (fn: FrameRequestCallback) => void; - let nativeSetTimeout: any = (global as any)[Zone.__symbol__('setTimeout')]; - if (!(global as any).requestAnimationFrame) { + let nativeSetTimeout: any = global[Zone.__symbol__('setTimeout')]; + if (!global.requestAnimationFrame) { nativeRequestAnimationFrame = function(fn: Function) { - (global as any)[Zone.__symbol__('setTimeout')](fn, 16); + global[Zone.__symbol__('setTimeout')](fn, 16); }; } else { nativeRequestAnimationFrame = getNativeRequestAnimationFrame().nativeRequestAnimationFrame; @@ -1135,7 +1136,7 @@ function commonTests() { beforeEach(() => { patchedImmediate = setImmediate; - (global as any).setImmediate = (global as any)[Zone.__symbol__('setImmediate')]; + global.setImmediate = global[Zone.__symbol__('setImmediate')]; coalesceZone = new NgZone({shouldCoalesceRunChangeDetection: true}); logs = []; coalesceZone.onMicrotaskEmpty.subscribe(() => { @@ -1144,7 +1145,7 @@ function commonTests() { }); afterEach(() => { - (global as any).setImmediate = patchedImmediate; + global.setImmediate = patchedImmediate; }); it('should run in requestAnimationFrame async', (done: DoneFn) => {