Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
Test component method that returns a Promise and performs action

I have an Angular component that has a method:

async update(myObject: IMyObject) {
    await this.myService
      .update(myObject)
      .toPromise()
      .then(updatedObject => {
        this.myObject = updatedObject.body;
      });
}

I am trying to write a unit test can cover the then part as well.

The async/await part makes it more difficult to test, I get a timeout after trying with the most common approaches.

The only thing that worked was:

const spyObj = spyOn(myService, 'update').and.callFake(() => {
        return Promise.resolve();
});

But obviously, that is not what I was looking for.

I would highly appreciate if you could point me in the correct direction.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!