Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda