Questions tagged [axios-mock-adapter]

82 questions
1
vote
0 answers

Axios mock adapter server returns a 404 ERROR

I have data in a local JSON file; to query that data, I'm using axios-mock-adapter. But for some reason, it's giving 404 not found. Not sure what I'm missing Exact error: GET http://localhost:3000/api/results 404 (Not Found) I have created a db…
Nauman
  • 894
  • 4
  • 14
  • 45
1
vote
1 answer

VueJS HTTP Tests - Mock not reflected in component render

I'm trying to complete some lightweight tests based on render output focussing on initial load and user interaction. I am working on a HTTP test for a login component. As you would expect, it's a basic component containing an email field, a password…
1
vote
0 answers

How can I cover Axios-retry failure unit testing using Mocha chai Nodejs?

How can we unit test the following code (axios-retry logic) AxiosRetryClass.ts import { AxiosInstance, AxiosRequestConfig } from 'axios'; import axiosRetry from 'axios-retry'; export class AxiosRetryClass { constructor() { } public…
Gnik
  • 7,120
  • 20
  • 79
  • 129
1
vote
1 answer

How to mock axios zip download call, using axios-mock-adaptor?

I have a code which is downloading the zip as arraybuffer and subsequently uses admZip to get the files inside. I am trying to unit test a method which calls this method and got stuck around mocking the zip download call. The code is - export const…
1
vote
1 answer

test rejecting an axios promise

I am trying to figure out how to correctly mock this code. I have figured out how to mock a success, but I cannot figure out how to mock the catch/reject block. App code: function getData(url = '') { return new Promise((resolve, reject) => { …
Tim B.
  • 446
  • 1
  • 5
  • 13
1
vote
0 answers

axios-mock-adapter: How to mock a binary response

Quite simular to that question I'd like to mock a PNG-Response with axios-mock-adapter. What I tried yet: import axios from 'axios' import MockAdapter from 'axios-mock-adapter' const fs = require('fs') new…
user470370
  • 572
  • 1
  • 5
  • 17
1
vote
1 answer

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.
  • 8,557
  • 11
  • 61
  • 89
1
vote
1 answer

Jest/Node Axios Testing Throwing Errors

Having an issue with running Jest testing with my lambda/node code. When I run the index.js the Axios get works fine. This is my index.js const sslRootCAs = require('ssl-root-cas/latest') const util = require('util') exports.handler = async…
Tim B
  • 215
  • 1
  • 2
  • 12
1
vote
3 answers

Verify request with axios-mock-adapter?

I made the following test using MockAdapter from axios-mock-adapter. However I'm trying to assert that the get function has effectively been called so I created a spy. For some reason it doesn't seem to work and I get:…
Flama
  • 772
  • 3
  • 13
  • 39
1
vote
1 answer

Using Jest to Mock Axios and Mock Windows.Location.Assignment

Some ReactJs component are using the Axios NPM library to fire off Http Posts. Using the post example from Axios, we have: axios.post('/user', { firstName: 'Fred', lastName: 'Flintstone' }) .then(function (response) { …
1
vote
2 answers

How can I return data brought from axios in React.js?

I'm working with this API: https://g6-ch2.herokuapp.com/api/usuarios/green. I'm trying to return data from it, but it doesn't return anything. I'm working with route parameters. Here is the code App.js: import Home from './components/Home' import…
1
vote
1 answer

Mock put requests with mock-axios-adapter

I have simple Vue component that fetches API key when it is created and key can be renewed by clicking on button: