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

211
Vistas
How to override AxiosInstance or Axios POST method in javascript to provide dummy response?

I have an application which makes call to a third party API using AXIOS. But instead of making actual third party call I would like to mock the 3rd party axios call based on some condition and provide my dummy response i.e, override the axios.post() method to provide my own implementation and provide success response.

Below is my code block where I would not want to pass the actual baseURL or if passed would like to call my override post() method and the dummy success response and not call the 3rd party endpoint. I want to do this in my code and not the Tests.

const axiosConfig = {
    baseURL: 'https://someURL.com',
    timeout: 60000, // 60 seconds
    responseType: 'json',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    },
  }
const myAxiosInstance = axios.create(axiosConfig);

const response = await myAxiosInstance.post('/somepath/to/the/resuource', somepayload);

How can I achieve this ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try this library: axios-mock-adapter

about 4 years ago · Juan Pablo Isaza Denunciar
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