javascript - 带有查询参数的 Testcafe 模拟请求/响应
问题描述
我正在尝试模拟使用查询参数的请求的响应。我已经在其他测试中使用过onrequestto,它可以无缝运行。已经有一个与我要问的问题类似的问题,但是无论我做什么,答案都对我不起作用:(
我的前端从后端获取数据的请求类似于
https://fake.com/search?Status=authorised&SortBy=Order
我在测试中所做的是:
import {RequestMock} from "testcafe";
const mock = RequestMock()
.onRequestTo('\/search\?Status=authorised')
.respond({data:ok}, 200, {'content-type': 'application/json charset=utf-8'})
fixture('Test suite')
.page('fake.com')
.requestHooks(mock);
并继续我的.test。OPTIONS 和 GET 请求都不会返回我期望的数据。我究竟做错了什么?
解决方案
onRequestTo
应该接收正则表达式值。因此,您必须将其更改为onRequestTo(/\/search\?Status=authorised/)
.
见https://testcafe.io/documentation/402763/reference/test-api/requestmock/onrequestto
推荐阅读
- java - Spring Boot,JPA / Hibernate:如何一次执行两个原始 SELECT 查询?
- reactjs - 从函数返回反应组件的问题
- python - 访问 spyder 历史日志
- react-native - 删除反应原生依赖
- javascript - 无论如何我可以使这个功能更简洁
- sql - 在日期时间字段上使用 IIF 输出字符串时 SQL Server 转换错误
- c# - OpenGL中的旋转问题
- python-asyncio - Asyncio RuntimeError: readuntil() 在另一个协程已经在等待传入数据时调用
- javascript - JavaScript 箭头函数创建 li 对象并添加到 HTML 页面
- python-3.x - Python Tkinter 在按钮单击时冻结