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

288
Views
Receiving a 'TypeError: axios.get.mockImplementationOnce is not a function' when using jest

I can't seem to figure out why my jest tests are throwing this error.

TypeError: axios.get.mockImplementationOnce is not a function

Here is my code:

./event.test.js

import axios from "axios";
import {jest} from '@jest/globals';
import ip from '../utils/ipv4.js';
import dotenv from 'dotenv';
import getEventByTitle from './eventTesting'
const result = dotenv.config({path: "../.env"});
if (result.error) throw result.error

const localhost = (process.env.IS_LOCAL == 'true') ? true : false;
const url = (localhost) ? `http://${ip}:${process.env.PORT}` : process.env.API_URL;

// Mock axios function
/*
jest.mock("axios", () => ({
  get: jest.fn(() => Promise.resolve({
    data: {}
  }))
}))
*/
jest.mock("axios")
// ^^ BOTH MOCK ATTEMPTS DONT WORK ^^

// TEST SUITE

test("Test imports", () => {
  expect(dotenv).toBeDefined()
  expect(ip).toBeDefined()
  expect(axios).toBeDefined()
})


describe('Axios test with mocking', () => {
  test("Test GET event", async () => {
  
    const fakeResponse = {
      title: "Mitchell's Dorm Party",
      host: 2,
      description: "Come to my party tonight in Leavey",
      location_id: 1,
      time: new Date("2021-11-06 10:50:00 PST")
    }

// TypeError: axios.get.mockImplementationOnce is not a function
    axios.get.mockImplementationOnce(() => 
      Promise.resolve({
        data: fakeResponse
      })
    )

    const result = await getEventByTitle("Mitchell's Dorm Party")
    expect(mockAxios.get).toHaveBeenCalledTimes(1);
    console.log(result)
  })
})

I'm not sure what I could be doing wrong and none of the documentation posted online has helped so far. Any advice would really be appreciated. Thanks!

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!