Questions tagged [axios-mock-adapter]

62 questions
1
vote
1 answer

axios-mock-adapter If I mock the requests then works only the requests that I mock

I'm trying to mock API that not implemented on server yet. But if I mock the requests then works only the requests that I mock. If I add mock.restore(); after mock.onGet then real API works fine, but then there is no mock API that I need too. import…
1
vote
1 answer

The reason of usage axios-mock-adapter

I'm a beginner to test axios calls and started using axios-mock-adapter but I don't get why we use axios-mock-adapter. mock.onPost('/api').reply(200, userData, headers); In this code snippet, does the request really go to the server or is this just…
Burak ULU
  • 275
  • 1
  • 5
  • 14
0
votes
0 answers

Possible to use Axios to mock API call from external library?

A component from an external library that my app uses will get an object from a a URL (say, https://external-library/getResource) and return it. import GetResource from "@external-library"; return ( <>

Got the thing below from…

0
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
  • 443
  • 8
  • 23
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
  • 9,841
  • 21
  • 103
  • 244
0
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,431
  • 16
  • 35
0
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 {…
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
  • 937
  • 2
  • 18
  • 38
0
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,175
  • 3
  • 35
  • 73
0
votes
0 answers

How to mock request from axios with axios-mock-adapter?

I try to mock my axios response from axios using axios-mock-adapter. First, I call get data API in use effect, when the response is success, then update my data state. This data state will show in FlatList, this is my view, const App = () => { …
0
votes
0 answers

How to Mock HTTP404 with axios-mock-adapter and custom error object

I have an overridden Axios function which helps me make API requests. the implementation of that function is that when the API call fails, it adds attributes in error.customAttributes. try { const data = await getMeDataPlease(param); } catch…
A.J.
  • 6,664
  • 10
  • 55
  • 74
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 Lê Quý
  • 486
  • 1
  • 5
  • 16
0
votes
0 answers

axios + axios-mock-adapter + redux-mock-store + redux-thunk + unit test case in jest

I am writing test for axios api. Here is my method. const getEmployees = () => (dispatch) => { dispatch(showLoader()) console.log(' ------------ calling ------- ') return axios .get('http://localhost:4000/api/employees') .then((res) =>…
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
0 answers

Writing e2e test for react.js component with jest

I'm trying to create e2e test for react.js function component using jest. Login.js - login component to test ... import { api } from '../helpers/api' ... const Login = () => { ... const onLogin = () => { ... api.post('/auth', { email:…
Ming Soon
  • 938
  • 2
  • 9
  • 30