detect-changes.md
December 8, 2023 · View on GitHub
🏠 → Documentation → Built-In Functionality → detectChanges
Other Predicates: attributes ・ callLifeCycleHook ・call ・ clicked ・ debug ・ detectChanges ・ emit ・ provider ・ state ・ waitFakeAsync
This predicate runs change detection. It optionally takes a configuration parameter which allows to further tweak its behavior.
Signature
detectChanges(opts?: DetectChangesOptions);
Interface DetectChangesOptions
interface DetectChangesOptions {
viaChangeDetectorRef?: boolean;
}
When setting viaChangeDetectorRef to true, this predicate will use the ChangeDetectorRef of the target(s) to enforce change detection. This is especially useful when the component-under-test uses ChangeDetectionStrategy.OnPush.
Examples
class the {
static OnlineStatusIcon {
return get(IconComponent);
}
}
it('should show the online-state as icon', () => {
When(host) // uses OnPush change-detection
.has(state({ online: false }))
.and(detectChanges({ viaChangeDetectorRef: true }))
.expect(the.OnlineStatusIcon)
.to(haveState({ icon: 'offline' }));
});