Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.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
Node.js 如何使用Jest测试Nestjs中的超时侦听器_Node.js_Typescript_Jestjs_Nestjs_Nestjs Testing - Fatal编程技术网

Node.js 如何使用Jest测试Nestjs中的超时侦听器

Node.js 如何使用Jest测试Nestjs中的超时侦听器,node.js,typescript,jestjs,nestjs,nestjs-testing,Node.js,Typescript,Jestjs,Nestjs,Nestjs Testing,我找不到任何关于如何在NestJS中测试拦截器的解释 请帮助我使用jest测试拦截器 从“@nestjs/common”导入{Injectable,NestInterceptor,ExecutionContext,CallHandler,RequestTimeoutException}; 从“rxjs”中导入{可观察的,抛出的,超时的}; 从“rxjs/operators”导入{catchError,timeout}; @可注射() 导出类TimeoutInterceptor实现NestInte

我找不到任何关于如何在NestJS中测试拦截器的解释

请帮助我使用jest测试拦截器

从“@nestjs/common”导入{Injectable,NestInterceptor,ExecutionContext,CallHandler,RequestTimeoutException};
从“rxjs”中导入{可观察的,抛出的,超时的};
从“rxjs/operators”导入{catchError,timeout};
@可注射()
导出类TimeoutInterceptor实现NestInterceptor{
构造函数(私有只读间隔:number){}
拦截(_context:ExecutionContext,next:CallHandler):可观察{
如果(此间隔>0){
返回next.handle().pipe(
超时(此时间间隔),
catchError((错误)=>{
if(TimeoutError的错误实例){
return-throwerr(new-RequestTimeoutException(`操作超时。`));
}
返回投掷器(错误);
}),
);
}
返回next.handle();
}
}

我曾经尝试过为这个拦截器编写单元测试,但我不喜欢:/Look: