Questions tagged [axios-mock-adapter]

62 questions
16
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
  • 2,493
  • 4
  • 26
  • 38
15
votes
4 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,059
  • 4
  • 21
  • 40
14
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
  • 1,580
  • 2
  • 23
  • 55
13
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
  • 279
  • 1
  • 4
  • 11
11
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
  • 299
  • 2
  • 3
  • 24
10
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
  • 695
  • 1
  • 7
  • 31
10
votes
2 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
  • 27,845
  • 80
  • 281
  • 473
7
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
  • 712
  • 1
  • 9
  • 30
7
votes
3 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
  • 9,589
  • 20
  • 104
  • 197
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
  • 309
  • 1
  • 12
5
votes
1 answer

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
  • 459
  • 6
  • 21
5
votes
0 answers

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
  • 674
  • 2
  • 8
  • 17
4
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
  • 695
  • 1
  • 5
  • 23
4
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
  • 91
  • 1
  • 4
3
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…
1
2 3 4 5