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

262
Vistas
Test fails on a simple function (jest + vue). It says the function wasn't called but actually console.log shows against

I have a simple login form with a username and password and submit button. When a user clicks submit button a function "login" is being called. This function describes the next behavior:

  1. if the username is empty then show notification by function showToast(msg)
  2. if the password is empty then show notification by function showToast(msg)
  3. if both username and password are presented, then send a request for authorization.
  4. After that I am waiting for a response from the request.
  5. If response contains "authToken" property then I write it in localStorage
  6. Else I check response status code in switch block.
  7. If code 401 then I show notification by function showToast(msg) about wrong credentials
  8. And by default I show notification by function showToast(msg) about any server error.

In my unit test, I want to test function "showTest" to check whether errors notifications are called.

Foreword: I have another case where I checked it and everything works properly.

My problem is that Jest says that the showToast function was not called, although in fact it is being called. And this can be seen in the logs.

So I put console.log in different places and due to them everything works in code but jest says that function showToast() wasn't called.

By the way, I mocked function in Vuex store which imitates request.

So how to fix this stupid and weird bug?

All code screenshots are attached.

login and showToast functions

mocked vuex action which imitates request

test case code

jest error

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