Questions tagged [axios-mock-adapter]
82 questions
22
votes
3 answers
How do you verify that a request was made with axios-mock-adapter?
I am using https://github.com/ctimmerm/axios-mock-adapter
I would like to know how can I verify that an endpoint was actually called by the system under test.
In this example:
var axios = require('axios');
var MockAdapter =…

Daryn
- 3,394
- 5
- 30
- 41
19
votes
4 answers
Axios catch error Request failed with status code 404
I'm testing a login component that uses Axios. I tried mocking Axios with axios-mock-adapter, but when I run the tests, it still errors out with:
Error: Request failed with status code 404
How do I properly mock Axios in my…

priyeshvadhiya
- 606
- 3
- 8
- 27
18
votes
5 answers
Mock api calls from Storybook
Does axios-mock-adapter only work on requests made with axios?
I have written a component that POSTs to an API (using vanilla XHR, not axios). I'm testing it in Storybook and want to intercept those POST requests since the endpoint doesn't exist…

Alan P.
- 2,898
- 6
- 28
- 52
16
votes
1 answer
Write test axios-mock-adapter with axios.create()
I want to test my http service but get error.
So, my test file
api.js
import axios from 'axios';
export const api = axios.create();
fetchUsers.js
import api from './api';
export const fetchUsers = (params) api.get('/api/users', { params })
…

user990993
- 309
- 1
- 5
- 12
15
votes
1 answer
Expecting an error with axios-mock-adapter
I am trying to test an axios get request with axios-mock-adapter, such that an error is thrown given a status that does not equal 200. However, when I execute the test (see api.test.js), I get the following message:
Error:…

Jimmy
- 3,090
- 12
- 42
- 99
14
votes
3 answers
Why TypeError: axios.create is not a function? When testing axios GET
I'm trying to test my axios API functions in React.
Found this question here: how do i test axios in jest which pointed to using axios-mock-adapter
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import chatbot from…

Leon Gaban
- 36,509
- 115
- 332
- 529
11
votes
2 answers
Why does my mock of my api return a 404 error?
I use axios-mock-adapter to mock my API, it works correctly but on one mock it returns a 404 error and I cannot found why.
There is here the sandbox with test, you can see when we run the test, the second check failed because the axios POST call…

Tryliom
- 895
- 1
- 12
- 37
10
votes
5 answers
Mock axios with axios-mock-adapter get undefined resp
I created an axios instance ...
// api/index.js
const api = axios.create({
baseURL: '/api/',
timeout: 2500,
headers: { Accept: 'application/json' },
});
export default api;
And severals modules use it ..
// api/versions.js
import api from…

ridermansb
- 10,779
- 24
- 115
- 226
8
votes
2 answers
How to work with path parameters in Axios Mock adapter
I am using axios mock adapter to mock the data for my react front-end. Currently I am working with param and it was working. But i need to support it to following url
.../invoice/1
This is my code
let mock;
if (process.env.REACT_APP_MOCK_ENABLED…

Pubudu Jayasanka
- 1,294
- 4
- 18
- 34
7
votes
2 answers
Testing Headers of Axios Request
I'm using Mocha + Chai and axios-mock-adapter for testing my axios request. It workes well, but I don't know how to test headers of axios by axios-mock-adapter and make sure Authorization and Content-type is correct!
export const uploadFile =…

Tran B. V. Son
- 759
- 2
- 12
- 31
6
votes
2 answers
Is it possible for partial data match with onPost() using axios-mock-adapter?
Environment:
NodeJS 8.1.2
axios 0.16.2
axios-mock-adapter 1.9.0
A test POST API call utilising JSONPlaceholder as follow:
const expect = require('chai').expect
const MockAdapter = require('axios-mock-adapter')
// Bootstrapping
const…

Trav L
- 14,732
- 6
- 30
- 39
5
votes
2 answers
how can i do a unit testing of axios.create mock with vitest?
i am learning unit testing in vue with typescript and i want to test this function
const getCLients =async (): Promise => {
const {data} = await clientsApi.get('/clients')
return data
}
But i got an error due to the…

alain_maza
- 71
- 4
5
votes
0 answers
How to fix "Unable to verify the first certificate" when testing axios-based API with JEST and axios-mock-adapter?
I'm using Jest and axios-mock-adapter to write tests for my API services. The problem is that when I run the test I get an error stating:
Error: unable to verify the first certificate.
app.service.js is the following
import ApiService from…

bba278
- 399
- 3
- 18
5
votes
1 answer
Cant mock axios api call with axios-mock-adapter in Storybook with Vuejs
Been trying to use storybook with my VueJS project and Im stuck with mocking api calls.
I tried using axios-mock-adapter without luck.
My storybook file code is:
import { storiesOf } from '@storybook/vue';
import { action } from…

badigard
- 820
- 2
- 10
- 22
5
votes
1 answer
How to wait for request to be finished with axios-mock-adapter like it's possible with moxios?
I try to test a rendering of some content after fetching it from server.
I use Vue Test Utils but this is irrelevant.
In the created hook of the component the ajax call is made with axios. I register the axios-mock-adapter response and 'render' the…

Paul Geisler
- 715
- 1
- 6
- 23