How can I wait for async ngOninit to complete before testing

Viewed 4126

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;
  })
};
1 Answers
Related