我正在尝试在测试期间切换来自模拟 API 的响应,以便我可以测试缓存选项。
所以基本上我想要的是我得到的第一个请求data1
,以及我得到的第二个请求data2
。
问题是,在第二个请求中,我仍然收到data1
,甚至认为我已经告诉 moxios 发送回来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)
});
});