Questions tagged [axios-mock-adapter]

82 questions
0
votes
0 answers

Axios mock adapter error when adding new routes for mock not working but existing is working

I have an issue when trying to add a new mock route. Cannot hit API mock with the new route but existing route is working. Currently /route/existing is working but /route/new is not working Is there any solution to this? Anyone also had experienced…
0
votes
0 answers

Mock axios with Typescript

In order to mock my rest call I'm using "axios-mock-adapter". My service where I'm triggering the call looks like this: export class ApiService { private static instance: ApiService private axiosInstance: AxiosInstance private…
Little Monkey
  • 5,395
  • 14
  • 45
  • 83
0
votes
0 answers

Vue3 Routes. Add navigation to a Json File

As part of learning Vue3 I am trying to piece together code that will mock API calls using Axios and a local Json file. However I am getting a 404 when accessing the file and suspect the route is not setup correctly. The data files are in my root…
0
votes
1 answer

how to fetch data from mock api in react?

I am using https://www.npmjs.com/package/axios-mock-adapter to fetch mock response .but I am not able to get mock response. here is my code https://codesandbox.io/s/frosty-surf-g9tezx?file=/src/App.js here I am fetching actual…
user5711656
  • 3,310
  • 4
  • 33
  • 70
0
votes
1 answer

How can I the improve speed of error responses when testing with React Query + Axios Mock Adapter?

I am writing tests for a component that uses React Query with Jest, React Testing Library, and Axios Mock Adapter (All requests are sent with axios) I want to ensure that an error message appears when axios returns a 500 error, and my test…
0
votes
0 answers

Failed to mock requests from suspended component

I have a component that waits until some data from a resource. I'm using React suspense to show the loading screen as until it gets the response. Everything work as expected. However when testing, even though onGet is registered, in axiosMock, it…
s1n7ax
  • 2,750
  • 6
  • 24
  • 53
0
votes
1 answer

abstract mock API response using MockAdapter with axios

I am using MockAdapter with axios to mock api response in storybook export const defaultAccountMockAPI = () => { const mock = new MockAdapter(axiosInstance); const defaultAccountDetails = objectKnob('Default Account Details',…
Yang Wang
  • 580
  • 4
  • 14
0
votes
0 answers

React JS: Testing async function usiing Jest is throwing error, "ReferenceError: regeneratorRuntime is not defined"

I am writing the unit tests/ integration tests for my React JS web application using Jest. The component I am testing is making an API call asynchronously. I am using this library, https://github.com/ctimmerm/axios-mock-adapter to mock the API…
Wai Yan Hein
  • 13,651
  • 35
  • 180
  • 372
0
votes
1 answer

Problem with use of Axios mock adapter GET

I try to use Axios mock adapter to simulate GET to Web API, but it does not work. The api url looks like something like that : `/api/forms/${guid}` I try using Regex, but doesn't work (probably something with the…
Jonathan Anctil
  • 1,025
  • 3
  • 20
  • 44
0
votes
1 answer

How can I mock error message when submit form with post method?

The project I just joined does not use an API from the backend but must create mock data by itself through the Axios-mock-adapter. I am making a form to change the password, if the inputs entered are correct, submit it will display successfully, if…
Nam Lee
  • 891
  • 1
  • 9
  • 20
0
votes
0 answers

Mock Axios instance and interceptors in React component jest test

I'm testing a component that calls an API to populate a table with data. Though axios is used, axios is being wrapped in a convenience method of sorts to populate headers before executing the request via interceptors. I've tried axios-mock-adapter,…
0
votes
1 answer

How to test axios get request in useEffect using Jest and Enzyme?

I am testing my axios get request using axois-mock-adapter, jest and enzyme. I a 404 error in my console when I run my tests. It started happening once I placed my axios call in useEffect. Any suggestions on what I might be doing wrong? Thanks in…
critical_maas
  • 127
  • 1
  • 3
  • 9
0
votes
0 answers

How to return value from an async function to it's parent function, so the parent function can also return this value?

I'm a beginner at Javascript, and I'm building an app to improve my skills. While making the login system for this app, I am having a problem with returning the data that I need from my 'main' parent function. This is the main function with 2…
0
votes
1 answer

axios-mock-adapter onGet mock data not effective

I'm trying to test axios call with axios-mock-adapter. I encountered following issue: The API calls from the test always respond to the real data instead of my mocked one with mock.onGet. a.k. receivedActions always from the real API call, but not…
Jimmy.H
  • 3
  • 1
  • 4
0
votes
1 answer

axios-mock-adapter error Error: Response for preflight has invalid HTTP status code 403

I am trying to write unit test by mocking axios api calls. Here is the axios-mock-adapter configuration import MockAdapter from 'axios-mock-adapter'; import axios from 'axios'; const mock = new MockAdapter(axios); it('Get User details without…