Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

axios

moxios

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 not certain what the most recent request would be. Even then, is there a another method to pop another request?

There doesn't seem to be any documentation on this on the moxios library here: https://github.com/axios/moxios

 let request = moxios.requests.mostRecent() // How to get 'some/url/' here? This expect is currently failing
      expect(request.url).to.equal('some/url/')
      request.respondWith({
        status: 200,
        response: []
}
like image 716
Helen Avatar asked Sep 12 '25 09:09

Helen


1 Answers

You can access requests by index like so: moxios.requests.at(0) for the first request, moxios.requests.at(1) for the next one and so on. I found that out here: https://github.com/axios/moxios/issues/10

like image 75
Peter Ngigi Avatar answered Sep 14 '25 01:09

Peter Ngigi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!