Con Jest, ¿hay alguna manera de burlarse de una promesa que nunca se resuelve? Quiero escribir una prueba de instantánea donde verifico mi IU en un estado de carga. El estado de carga depende de una promesa. Si la promesa se resuelve, el estado de carga desaparece.
Modelo:
<div v-if="isLoading"> <div>Starting service, please wait</div> </div>Guion:
async startService() { try { this.isLoading = true; const response = await this.service.start(); this.isLoading = false; }Prueba propuesta:
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(); });