reactjs - 如何使用 toHaveBeenCalledWith 仅检查 URL?
问题描述
我正在测试一个 API,并想检查是否使用了正确的 api URL。现在看来我可以使用toHaveBeenCalledWith了。但是,它会返回该请求选项中的所有内容:
Expected: "http://localhost:5000/myUrls"
Received: "http://localhost:5000/myUrl", {"headers": {"Authorization": "Bearer foobar", "Content-Type": "application/json", "X-Request-ID": "15863752509339714997334447706"}}
仅检查 url 的常见做法是什么?
解决方案
您可以将第二个参数指定为任何值:
expect(fn).toHaveBeenCalledWith(
"http://localhost:5000/myUrls",
expect.anything()
);
推荐阅读
- php - 在 Laravel 中调用过程时如何获取自定义 sql srv 变量或结果集的值?
- forms - 提交后如何清理值字段symfony表单
- javascript - 传单:如何从水平重复的单个图像制作地图?
- powerbi - 列颜色格式在 POWER BI 中无法正常工作
- oracle - 应该使用多行和多列进行分组时如何使用 Group By?
- swift - 为什么我的应用程序委托文件 SwiftUI 没有输出
- python - 无法使用 bs4 python 识别正确的“div”
- python - python字典默认值
- reactjs - 如何在选择选项上对 JSON 文件的键进行分组?
- web - GrapeCity ActiveReports web-designer.js 的文档