I have an ngOnInit
method that does async work.
How can I execute my expect
statements once the async work is complete ?
it('test things once all the promises declared in ngOninit are resolved', () => {
comp.ngOnInit();
// I want to test that comp.property is like expected
});
My component methods look like this:
OnInit() {
this.asyncMethod();
};
asyncMethod() {
this.methodThatReturnsPromise().then(() => {
this.property = this.otherPropertyNowResolved;
})
};
fixture = TestBed.createComponent(MyComponent);
it('test things once all the promises declared in ngOninit are resolved', async(() => {
fixture.detectChanges();
fixture.whenStable().then(
() => {
// This should run once ngOnInit is completed
}
);
}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With