Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

122
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda