如何在 fetch-mock 中模拟多个获取?

How to mock several gets in fetch-mock?

我正在测试我的反应组件,我想模拟几个 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.

我该怎么做?

使用overwriteRoutes选项

test(`Created correctly`, async () => {
    fetchMock.get(`*`, JSON.stringify(FIRSTGETOBJ));
    fetchMock.get(`*`, JSON.stringify(SECONDGETOBJ), { overwriteRoutes: false });
    fetchMock.get(`*`, JSON.stringify(THIRDGETOBJ), { overwriteRoutes: false });

    //...
}