-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-setup.ts
More file actions
35 lines (30 loc) · 1.31 KB
/
test-setup.ts
File metadata and controls
35 lines (30 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Source: https://github.com/angular/angular/issues/12313#issuecomment-561221167
import { ChangeDetectorRef, Type } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
function runOnPushChangeDetection<T>(cf: ComponentFixture<T>): () => Promise<void> {
return async () => {
const cd: ChangeDetectorRef = cf.debugElement.injector.get<ChangeDetectorRef>(ChangeDetectorRef as any);
cd.detectChanges();
await cf.whenStable();
};
}
export const improveChangeDetection = () => {
const originalCreate = TestBed.createComponent;
TestBed.createComponent = <T>(component: Type<T>) => {
const componentFixture: ComponentFixture<T> = originalCreate(component);
componentFixture.detectChanges = runOnPushChangeDetection(componentFixture);
return componentFixture;
};
};
// Source: https://github.com/ionic-team/ionic-framework/issues/19926#issuecomment-724188621
export const muteIonicReInitializeWarning = () => {
const originalWarn = console.warn;
const patchedWarn = (warning: any, ...optionalParameters: any[]) => {
const suppress = `Ionic Angular was already initialized. Make sure IonicModule.forRoot() is just called once.`;
if (warning === suppress) {
return;
}
originalWarn(warning, ...optionalParameters);
};
console.warn = patchedWarn;
};