我正在测试我的反应组件,我想模拟几个get
操作。我想做的是:
test(`Created correctly`, async () => {
fetchMock.get(`*`, JSON.stringify(FIRSTGETOBJ));
fetchMock.get(`*`, JSON.stringify(SECONDGETOBJ));
fetchMock.get(`*`, JSON.stringify(THIRDGETOBJ));
//...
}
每个get
的网址都相同,但有效负载会发生变化。但是,使用上面的代码我会得到:
Error: Adding route with same name as existing route. See `overwriteRoutes` option.
我该怎么做?
答案 0 :(得分:7)
使用overwriteRoutes
选项
test(`Created correctly`, async () => {
fetchMock.get(`*`, JSON.stringify(FIRSTGETOBJ));
fetchMock.get(`*`, JSON.stringify(SECONDGETOBJ), { overwriteRoutes: false });
fetchMock.get(`*`, JSON.stringify(THIRDGETOBJ), { overwriteRoutes: false });
//...
}