问题描述
限时送ChatGPT账号..我的请求 url 有多个查询参数.我想在 Testcafe 中编写测试时模拟外部 API 的响应.我想在 E2E 测试中模拟数据,因为我的数据每 15 天就会过期.请建议一些方法来处理使用查询参数模拟请求.我可以模拟没有任何查询参数的请求,我为此使用了请求钩子.
My request url has multiple query params. I want to mock the response of the external API while writing my tests in Testcafe. I want to mock the data in E2E testing because my data will expire in every 15days. Please suggest some ways to handle mocking the request with query param. I am able to mock the request not having any query param and I am using Request Hooks for that.
推荐答案
来自带参数和不带参数的 URL 的模拟响应之间应该没有区别.您可以使用 RequestMock
API:
There shouldn't be a difference between a mocking response from URL with parameters and without them. You can mock a response by using RequestMock
API:
...
const getDataMock = RequestMock()
.onRequestTo(/.*getData\?param=param_1/)
.respond((req, res) => {
res.setBody({...});
});
...
如果这对您不起作用,请向我们提供您定义 RequestMock
或 RequestHook
的代码.
If this doesn't work for you, please provide us with the code where you define RequestMock
or RequestHook
.
这篇关于如何在 Testcafe 中使用请求钩子模拟时传递请求 url 的查询参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论