Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
测试HttpInterceptor Angular 10时出错_Angular_Typescript_Testing_Angular Httpclient_Angular Httpclient Interceptors - Fatal编程技术网

测试HttpInterceptor 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

我正在开发一个Angular 10应用程序,它使用一个
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
    函数
  • 非常感谢您的帮助,谢谢