Questions tagged [axios-mock-adapter]
82 questions
5
votes
1 answer
How can I test async axios requests in redux-saga?
I have a saga of the form:
export function* apiRequest(apiBaseUrl, action) {
const axiosInst = getAxiosInst(apiBaseUrl);
try {
if (!action.serviceName) {
throw new Error("No service name provided");
}
const response = yield…

13tales
- 131
- 1
- 4
4
votes
2 answers
Axios mock adapter giving error 'Error: Request failed with status code 404'
I have a component in which I am making an API call on mount
import * as React from 'react';
import axios from 'axios';
import './index.scss';
// import {axiosInstance} from '../../mocks/index';
// axios(client)
// axiosInstance(axios);
const…

Aayushi
- 1,736
- 1
- 26
- 48
4
votes
1 answer
How to mocking a http request with route params using axios-mock-adapter
How to mock http request with route params?
var axios = require('axios');
var MockAdapter = require('axios-mock-adapter');
// This sets the mock adapter on the default instance
var mock = new…

Gopal Jee purwar
- 41
- 1
- 3
3
votes
0 answers
mocking all axios instances with axios-mock-adapter
Unfortunatelly, attempting to mock the whole axios package in jest test (as below) when axios.create is called somewhere doesn't work:
import axios from 'axios'
import AxiosMockAdapter from 'axios-mock-adapter'
const axiosMock = new…

Syffys
- 570
- 5
- 21
3
votes
1 answer
Include JS module/file only in development-mode
How can I conditionally import a module only in development mode (in my case the axios-mock-adapter package). Also the code should not even be present in the production bundle.
Example code I only want to be included during development:
export const…

mleister
- 1,697
- 2
- 20
- 46
2
votes
1 answer
Axios Network error on post request React.js but works on Postman
I did a post request in Postman with adding Api-key in header from Authorization options which works completely fine but when i tried to do the same thing in React.js it gives me Network error. I think i'm missing anythink in my post request but…

Sharanjeet Singh
- 89
- 7
2
votes
1 answer
axios-mock-adapter breaks when used on axios.create() instance after first test
I am using axios-mock-adapter to test my components. The strange thing is that only a single test can be run successfully because the next one always breaks. Each test works fine if run individually.
Here is my setup.
"axios-mock-adapter":…

CodeSamurai777
- 3,285
- 2
- 24
- 42
2
votes
1 answer
axios get 404 because axios mock adapter
I bought Metronic React template with axios-mock-adapter inside. I still need mock request for Authentication, but when I use Axios to fetch public API with Axios.get() returned 404 or undefined (see my redux modules below).
redux modules
import {…

arioamri
- 35
- 5
2
votes
1 answer
Axios mock adapter returns 404 on all reqeusts
When trying to setup axios to mock requests to an incomplete api server I'm using to build a front end, I am getting 404 responses on all requests, even those that aren't mocked at all.
const api = axios.create({
baseURL:…

richbai90
- 4,994
- 4
- 50
- 85
2
votes
1 answer
Can I use jest.fn() related checks with axios-mock-adapter?
I'm using axios-mock-adapter and I want to know if I can set it up so that I can also make assertions like expect(MockAdapter.get).toHaveBeenCalledWith(url);
I've tried the following:
// test
import MockAdapter from "axios-mock-adapter";
import {…

Jonathan Tuzman
- 11,568
- 18
- 69
- 129
2
votes
1 answer
Is it possible to apply passThrough() within a mock reply using axios-mock-adapter?
Environment:
NodeJS 8.1.2
axios 0.16.2
axios-mock-adapter 1.9.0
Testing a JSON-RPC endpoint, am I able to do something like this:
const mockHttpClient = new MockAdapter(axios, { delayResponse: 50 })
mockHttpClient.onPost().reply((config) => { //…

Trav L
- 14,732
- 6
- 30
- 39
1
vote
1 answer
Cant make axios-mock-adpter work properly
I trying to implement the axios-mock-adpter just for mock (not unit test) while the backend do they work.
Im using Nextjs V.13,axios and axios-mock-adpter
1-AxiosMock and Mock Initializer
import axios from "axios";
import MockAdapter from…

Willien
- 25
- 4
1
vote
2 answers
"TypeError: mock.onGet is not a function" while mocking axios with axios-mock-adapter
I'm trying a very basic test given in axios-mock-adapter homepage, but getting the above error. Any help is highly appreciated.
src/fakeAxios.spec.js:
var axios = require("axios");
var MockAdapter = require("axios-mock-adapter");
it("fakeAxios",…

vd1
- 11
- 3
1
vote
1 answer
axios-mock-adapter: MockAdapter constructor returns promise in test file
I'm trying to use "axios-mock-adapter" lib to mock my API requests.
Following the documentation, I need to create an instance of MockAdapter and use it in test cases. But actually, it returns a Promise and follows the next error "mock.onGet is not a…

Oleksandr Voronkov
- 11
- 1
1
vote
1 answer
Axios request getting mixed up with mock requests: TypeError: mockAdapter.originalAdapter is not a function
I have axios and axios-mock-adapter installed in my nextjs app, but when the Axios request running in localhost:3000 tries to call an AWS Lambda request (that I know works), I'm getting the error:
Goals (get) api error: TypeError:…

Clarkie
- 39
- 7