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

290
Visualizações
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
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