wait-fake-async.md
December 8, 2023 · View on GitHub
🏠 → Documentation → Built-In Functionality → waitFakeAsync
Other Predicates: attributes ・ callLifeCycleHook ・call ・ clicked ・ debug ・ detectChanges・ emit ・ provider ・state ・waitFakeAsync
This predicate waits the specified amount of time within a fakeAsync-zone.
Please Note
This predicate only works in a
fakeAsync-zone. If not called in afakeAsync-zone it will throw causing the test case to fail.
Signature
waitFakeAsync(modeOrMs?: 'animationFrame' | number);
Example
import { state, waitFakeAsync, haveText, haveEmitted } from '@centigrade/ngtx';
import { fakeAsync } from '@angular/core/testing';
import { of } from 'rxjs';
class the {
static GreetingLabel() {
return get('h2');
}
}
it('should render the correct welcome message', fakeAsync(() => {
When(host)
.has(state({ userName$: of('Ann') }))
.and(waitFakeAsync())
.expect(the.GreetingLabel)
.to(haveText('Welcome Ann!'));
}));
it('[Popup] should emit a close event after five seconds', fakeAsync(() => {
When(host)
.rendered()
.and(waitFakeAsync(5000))
.expect(host)
.to(haveEmitted('close'));
}));