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

212
Views
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 answers
Answer question

0

Try this library: axios-mock-adapter

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