如何在 Testcafe 中使用 Request Hooks 模拟时传递请求 url 的查询参数?

How to pass query params of a request url while mocking with Request Hooks in Testcafe?

我的请求 url 有多个查询参数。我想在 Testcafe 中编写测试时模拟外部 API 的响应。我想在E2E测试中模拟数据,因为我的数据每15天就会过期。 请提出一些方法来处理使用查询参数模拟请求。我能够模拟没有任何查询参数的请求,我正在为此使用 Request Hooks。

来自 URL 的带参数和不带参数的模拟响应之间应该没有区别。您可以使用 RequestMock API:

模拟响应
...
const getDataMock = RequestMock()
    .onRequestTo(/.*getData\?param=param_1/)
    .respond((req, res) => {
        res.setBody({...});
    });
...

如果这对您不起作用,请向我们提供您定义 RequestMockRequestHook.

的代码