javascript - Moxios 在测试期间未更改 stubRequest 返回数据
问题描述
我正在尝试在测试期间切换来自模拟 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)
});
});
解决方案
推荐阅读
- nonlinear-optimization - 在 OpenMDAO 中,有没有办法确保在继续计算之前遵守约束?
- kubernetes - AWS EBS 如何获取文件更改通知
- r - 循环遍历函数并将输出堆叠到 R 中的数据集中
- git - 您不能推送“serena@ai.com”的提交。您只能推送使用您自己的已验证电子邮件之一提交的提交
- python - 如何将条形图和折线图一起绘制并用日期格式化 x 轴
- python - 当输入字符串与键字符串相同时,做一些事情
- pine-script - 将研究脚本转换为策略时,Pinescript 中出现未声明的标识符错误
- python - 使用 Python SDK 在 GCP 中获取区域集群
- python - 耦合两个不同的非继承类参数/变量的最佳方式
- c - 关于 C 中的幂和缩进