Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!