我正在测试我的react组件,我想模拟几个get操作。我想要做的是:
test(`Created correctly`, async () => {
fetchMock.get(`*`, JSON.stringify(FIRSTGETOBJ));
fetchMock.get(`*`, JSON.stringify(SECONDGETOBJ));
fetchMock.get(`*`, JSON.stringify(THIRDGETOBJ));
//...
}每个get的url是相同的,但有效负载发生了变化。但是,使用上面的代码,我将获得:
Error: Adding route with same name as existing route. See `overwriteRoutes` option.我该怎么做呢?
发布于 2018-03-28 20:45:08
使用overwriteRoutes选项
test(`Created correctly`, async () => {
fetchMock.get(`*`, JSON.stringify(FIRSTGETOBJ));
fetchMock.get(`*`, JSON.stringify(SECONDGETOBJ), { overwriteRoutes: false });
fetchMock.get(`*`, JSON.stringify(THIRDGETOBJ), { overwriteRoutes: false });
//...
}https://stackoverflow.com/questions/49031208
复制相似问题