Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Moxios not changing stubRequest return data during test

I'm trying to switch responses from the mocked out API during a test, so that I can test a caching option.

So basically what I want is that on the first request I get data1, and on the second request I get data2.

The problem is that on the second request, I am still getting data1, even thought I have told moxios to send back data2.

describe("getDataWithCache", () => {
  it("should fetch data1 on first request and data2 on second request", () => {
    moxios.stubRequest(testUrl, data1)
    const response1 = await makeApiCall(testUrl)
    expect(response1.data.name).toBe(data1.name)

    // This is the line of code where the problem is occurring, because it isn't changing
    // the mock data being returned
    moxios.stubRequest(testUrl, data2)
    const response2 = await makeApiCall(testUrl)
    expect(response2.data.name).toBe(data2.name)
  });
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!