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

211
Vistas
Mock promise that never resolves with Jest

With Jest, is there a way to mock a promise that never resolves? I want to write a snapshot test where I verify my UI in a loading state. The loading state depends on a promise. If the promise resolves, the loading state goes away.

Template:

<div v-if="isLoading">
  <div>Starting service, please wait</div>
</div>

Script:

async startService() {
    try {
      this.isLoading = true;
      const response = await this.service.start();
      this.isLoading = false;
    }

Proposed test:

it('loading screen should display', async() => {
  const startServiceSpy = jest
    .spyOn(Service.prototype, 'start')
    .mockImplementation(() =>
      DO NOT RESOLVE SERVICE CALL HERE
    }));

  wrapper.vm.startService();

  // show loading screen in snapshot
  expect(wrapper.html()).toMatchSnapshot();

});
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