gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 17:30:38 27 4
gpt4 key购买 nike

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

我怎样才能做到这一点?

最佳答案

使用 overwriteRoutes选项

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

//...
}

关于unit-testing - 如何在 fetch-mock 中模拟多个获取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49031208/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com