测试HttpInterceptor Angular 10时出错
我正在开发一个Angular 10应用程序,它使用一个测试HttpInterceptor Angular 10时出错,angular,typescript,testing,angular-httpclient,angular-httpclient-interceptors,Angular,Typescript,Testing,Angular Httpclient,Angular Httpclient Interceptors,我正在开发一个Angular 10应用程序,它使用一个HttpInterceptor为所有响应添加一个特定的头。不幸的是,在尝试测试此拦截器时,我一直遇到以下错误: Error: Expected one matching request for criteria "Match by function: ", found none. 或类似的变体: Error: Expected one matching request for criteria "Match U
HttpInterceptor
为所有响应添加一个特定的头。不幸的是,在尝试测试此拦截器时,我一直遇到以下错误:
Error: Expected one matching request for criteria "Match by function: ", found none.
或类似的变体:
Error: Expected one matching request for criteria "Match URL: /endpoint", found none.
我的期望是这个测试会通过,但我现在不知道为什么它不起作用
这是我的拦截器:
@Injectable()
导出类AuthInterceptor实现HttpInterceptor{
构造函数(私有kc:keydeposervice){}
截取(请求:HttpRequest:
在这里,我发现了一个有用的工具,它几乎完全满足了我的需要,但实际上并不适用于我的案例(我得到了上面的错误)。我说得几乎完全正确,因为我用来获取令牌的服务实际上没有使用HttpClient
与我的问题不完全一样,但它非常相似,可以尝试一下。我尝试使用教科书中描述的解决方法,但显然这与我遇到的问题还不够接近
我还尝试了spyOn
测试中的http.get(…)
函数,这导致上述错误被消除,但当我这样做时,它没有调用我的intercept
函数
非常感谢您的帮助,谢谢