我正在测试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的常见做法是什么?
答案 0 :(得分:2)
您可以将第二个参数指定为任意值:
expect(fn).toHaveBeenCalledWith(
"http://localhost:5000/myUrls",
expect.anything()
);