Last active
February 17, 2022 17:15
-
-
Save ali-kamalizade/14f7f0ab19f6592adf2f05cd6215dabf to your computer and use it in GitHub Desktop.
A function which can be used in Angular component tests to trigger change detection for components using OnPush strategy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Changes in components using OnPush strategy are only applied once when calling .detectChanges(), | |
* This function solves this issue. | |
*/ | |
export async function runOnPushChangeDetection(fixture: ComponentFixture<any>): Promise<void> { | |
const changeDetectorRef = fixture.debugElement.injector.get<ChangeDetectorRef>(ChangeDetectorRef); | |
changeDetectorRef.detectChanges(); | |
return fixture.whenStable(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment