【发布时间】:2019-10-29 17:44:06
【问题描述】:
在我的 Angular 应用程序中,我正在测试使用 HttpClient 的服务,就像官方文档建议的那样:
https://angular.io/guide/http#testing-http-requests
这就是我的测试用例的样子:
it('myMethod() should correctly sent the http request', () => {
const mockResultData = { result: 123 };
service.myMethod(); // will trigger an http request using the httpClient
const req = httpTestingController.expectOne('/some/path?param1=a¶m2=b');
expect(req.request.method).toEqual('GET');
req.flush(mockResultData);
httpTestingController.verify();
});
但是测试失败并出现以下情况:
错误:预期有一个条件匹配请求“匹配 URL: /some/path?param1=a¶m2=b",没有找到。
现在我很清楚触发的请求并不完全是 url /some/path?param1=a&param2=b,但是 错误消息没有提到找到了哪些请求。
如何调试并检查实际找到了哪些请求?
【问题讨论】:
标签: angular typescript jasmine angular-httpclient angular-test