Questions tagged [moxios]

Moxios is a request mocking framework for axios, JavaScript HTTP client.

46 questions
8
votes
1 answer

Matching axios POST request with moxios

Is it possible to use moxios to mock a reply to a POST request that will match not just by URL but also by the POST body? Inspecting the body afterwards would work for me too. This is what I am doing now. As far as I know there are no method…
MartinTeeVarga
  • 10,478
  • 12
  • 61
  • 98
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
4
votes
1 answer

Mock multiple api call inside one function using Moxios

I am writing a test case for my service class. I want to mock multiple calls inside one function as I am making two API calls from one function. I tried following but it is not working it('should get store info', async done => { const store:…
Jitender
  • 7,593
  • 30
  • 104
  • 210
4
votes
1 answer

`moxios.wait` never executes when testing VueJS with Jest, Vue Test Utils and Moxios

I'm trying to write my first unit test for a VueJS component that grabs some data from an API endpoint when it renders: My VueJS component: import axios from 'axios'; export default { props: { userIndexUrl: { required: true …
Constant Meiring
  • 3,285
  • 3
  • 40
  • 52
4
votes
1 answer

Moxios: How to access requests that aren't the most recent in unit tests

A have a page that on render sends out multiple HTTP get requests for data. How do I filter through moxios.requests to get the request with a certain URL to respond to? The only method I can find online is moxios.requests.mostRecent(), however I'm…
Helen
  • 727
  • 8
  • 13
4
votes
1 answer

Testing debounced asynchronous request with moxios and fakeTimers

I’m trying to test an axios call in a debounced method, but moxios.wait() always times out if I add fake timers. The test works without the clock, if the debounce time is set small enough (e.g. 10ms) but that doesn’t help testing proper…
Alex
  • 631
  • 1
  • 8
  • 33
4
votes
2 answers

How would one mock an axios.all request?

I've came across this wall while i was mocking my project. I make an axios.all request with 10 requests within it. How the hell do i mock it? I'm currently using moxios to mock my axios http requests but it doesn't seem to have the functionality to…
3
votes
1 answer

Testing if a function is called inside another function Jest

I am writing a Redux action to fulfill a unit test a but am having trouble with the mocked function call inside the test. I believe I have mocked completeRegistration correctly, by importing the module it is declared in and then mocking the function…
andy
  • 81
  • 11
3
votes
0 answers

Moxios not using stubbed request

I am working through a udemy course and it's on the testing portion. In it, the instructor uses moxios to stub requests. However, it is not using the stubbed response. The stubbed response should only be returning 2 items, where as the actual API…
3
votes
3 answers

Moxios - TypeError: Cannot read property 'adapter' of undefined

Trying to test axios calls and trying the moxios package. "axios": "^0.16.2", "moxios": "^0.4.0", Found here: https://github.com/axios/moxios Following there example, but my test errors out on the moxios.install() line: import axios from…
Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
3
votes
1 answer

Mocking Axios calls using Moxios in order to test API calls

I have the following custom Axios instance: import axios from 'axios' export const BASE_URL = 'http://jsonplaceholder.typicode.com' export default axios.create({ baseURL: BASE_URL }) With the corresponding service: import http from…
César Alberca
  • 2,321
  • 2
  • 20
  • 32
2
votes
1 answer

How to get react test using moxios to update the DOM before running later part of the test

I am trying to write a test using jest and react-testing-library for a component. The test needs to wait for useEffect to update the state following an axios request. I'm using moxios to mock the api call but I can't get the test to wait for moxios…
2
votes
1 answer

Wrapping async moxios call in act callback

I am trying to test a react functional component using hooks. The useEffect hook makes a call to a third part API which then calls setState on return. I have the test working but keep getting a warning that an update to the component was not wrapped…
2
votes
1 answer

How to mock an axios class

I am writing tests for my asynchronous actions. I have abstracted away my axios calls into a separate class. If I want to test my asynchronous redux action, how do I write a mock for api.js so that sampleAction.test.js will pass? Thanks! api.js:…
Jimmy
  • 3,090
  • 12
  • 42
  • 99
2
votes
1 answer

Jest with moxios keeps timing out when I use custom axios instance

I have a service that uses a custom axios instance that I am trying to test but I keep getting an error. Here is the error: : Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout. Here is the test: import…
MMelvin0581
  • 509
  • 6
  • 20
1
2 3 4