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
This commit is contained in:
parent
87873ed422
commit
30a24b6bf5
|
@ -14,6 +14,7 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||||
import {ivyEnabled, onlyInIvy} from '@angular/private/testing';
|
import {ivyEnabled, onlyInIvy} from '@angular/private/testing';
|
||||||
|
|
||||||
import {domRendererFactory3} from '../../src/render3/interfaces/renderer';
|
import {domRendererFactory3} from '../../src/render3/interfaces/renderer';
|
||||||
|
import {global} from '../../src/util/global';
|
||||||
|
|
||||||
|
|
||||||
describe('component', () => {
|
describe('component', () => {
|
||||||
|
@ -304,7 +305,7 @@ describe('component', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with ngDevMode', () => {
|
describe('with ngDevMode', () => {
|
||||||
const _global: {ngDevMode: any} = global as any;
|
const _global: {ngDevMode: any} = global;
|
||||||
let saveNgDevMode!: typeof ngDevMode;
|
let saveNgDevMode!: typeof ngDevMode;
|
||||||
beforeEach(() => saveNgDevMode = ngDevMode);
|
beforeEach(() => saveNgDevMode = ngDevMode);
|
||||||
afterEach(() => _global.ngDevMode = saveNgDevMode);
|
afterEach(() => _global.ngDevMode = saveNgDevMode);
|
||||||
|
|
|
@ -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 {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 {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
||||||
|
|
||||||
|
import {global} from '../../src/util/global';
|
||||||
import {scheduleMicroTask} from '../../src/util/microtask';
|
import {scheduleMicroTask} from '../../src/util/microtask';
|
||||||
import {getNativeRequestAnimationFrame} from '../../src/util/raf';
|
import {getNativeRequestAnimationFrame} from '../../src/util/raf';
|
||||||
import {NoopNgZone} from '../../src/zone/ng_zone';
|
import {NoopNgZone} from '../../src/zone/ng_zone';
|
||||||
|
@ -982,10 +983,10 @@ function commonTests() {
|
||||||
|
|
||||||
describe('shouldCoalesceEventChangeDetection = true, shouldCoalesceRunChangeDetection = false', () => {
|
describe('shouldCoalesceEventChangeDetection = true, shouldCoalesceRunChangeDetection = false', () => {
|
||||||
let nativeRequestAnimationFrame: (fn: FrameRequestCallback) => void;
|
let nativeRequestAnimationFrame: (fn: FrameRequestCallback) => void;
|
||||||
let nativeSetTimeout: any = (global as any)[Zone.__symbol__('setTimeout')];
|
let nativeSetTimeout: any = global[Zone.__symbol__('setTimeout')];
|
||||||
if (!(global as any).requestAnimationFrame) {
|
if (!global.requestAnimationFrame) {
|
||||||
nativeRequestAnimationFrame = function(fn: Function) {
|
nativeRequestAnimationFrame = function(fn: Function) {
|
||||||
(global as any)[Zone.__symbol__('setTimeout')](fn, 16);
|
global[Zone.__symbol__('setTimeout')](fn, 16);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
nativeRequestAnimationFrame = getNativeRequestAnimationFrame().nativeRequestAnimationFrame;
|
nativeRequestAnimationFrame = getNativeRequestAnimationFrame().nativeRequestAnimationFrame;
|
||||||
|
@ -996,7 +997,7 @@ function commonTests() {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
patchedImmediate = setImmediate;
|
patchedImmediate = setImmediate;
|
||||||
(global as any).setImmediate = (global as any)[Zone.__symbol__('setImmediate')];
|
global.setImmediate = global[Zone.__symbol__('setImmediate')];
|
||||||
coalesceZone = new NgZone({shouldCoalesceEventChangeDetection: true});
|
coalesceZone = new NgZone({shouldCoalesceEventChangeDetection: true});
|
||||||
logs = [];
|
logs = [];
|
||||||
coalesceZone.onMicrotaskEmpty.subscribe(() => {
|
coalesceZone.onMicrotaskEmpty.subscribe(() => {
|
||||||
|
@ -1005,7 +1006,7 @@ function commonTests() {
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
(global as any).setImmediate = patchedImmediate;
|
global.setImmediate = patchedImmediate;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should run in requestAnimationFrame async', (done: DoneFn) => {
|
it('should run in requestAnimationFrame async', (done: DoneFn) => {
|
||||||
|
@ -1121,10 +1122,10 @@ function commonTests() {
|
||||||
|
|
||||||
describe('shouldCoalesceRunChangeDetection = true', () => {
|
describe('shouldCoalesceRunChangeDetection = true', () => {
|
||||||
let nativeRequestAnimationFrame: (fn: FrameRequestCallback) => void;
|
let nativeRequestAnimationFrame: (fn: FrameRequestCallback) => void;
|
||||||
let nativeSetTimeout: any = (global as any)[Zone.__symbol__('setTimeout')];
|
let nativeSetTimeout: any = global[Zone.__symbol__('setTimeout')];
|
||||||
if (!(global as any).requestAnimationFrame) {
|
if (!global.requestAnimationFrame) {
|
||||||
nativeRequestAnimationFrame = function(fn: Function) {
|
nativeRequestAnimationFrame = function(fn: Function) {
|
||||||
(global as any)[Zone.__symbol__('setTimeout')](fn, 16);
|
global[Zone.__symbol__('setTimeout')](fn, 16);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
nativeRequestAnimationFrame = getNativeRequestAnimationFrame().nativeRequestAnimationFrame;
|
nativeRequestAnimationFrame = getNativeRequestAnimationFrame().nativeRequestAnimationFrame;
|
||||||
|
@ -1135,7 +1136,7 @@ function commonTests() {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
patchedImmediate = setImmediate;
|
patchedImmediate = setImmediate;
|
||||||
(global as any).setImmediate = (global as any)[Zone.__symbol__('setImmediate')];
|
global.setImmediate = global[Zone.__symbol__('setImmediate')];
|
||||||
coalesceZone = new NgZone({shouldCoalesceRunChangeDetection: true});
|
coalesceZone = new NgZone({shouldCoalesceRunChangeDetection: true});
|
||||||
logs = [];
|
logs = [];
|
||||||
coalesceZone.onMicrotaskEmpty.subscribe(() => {
|
coalesceZone.onMicrotaskEmpty.subscribe(() => {
|
||||||
|
@ -1144,7 +1145,7 @@ function commonTests() {
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
(global as any).setImmediate = patchedImmediate;
|
global.setImmediate = patchedImmediate;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should run in requestAnimationFrame async', (done: DoneFn) => {
|
it('should run in requestAnimationFrame async', (done: DoneFn) => {
|
||||||
|
|
Loading…
Reference in New Issue