【发布时间】:2021-12-03 18:52:32
【问题描述】:
我有一个 Loopback 4 控制器,我想对它进行单元测试。如何模拟请求参数?这是我的控制器的构造函数:
constructor(@inject(RestBindings.Http.REQUEST) private req: Request,
@service(HttpService) private httpService: HttpService,
@service(LocalRequestService) private localRequestService: LocalRequestService) {}
我尝试用createStubInstance(Request) 模拟它,但这给了我这个错误:
Argument of type 'StubbedInstanceWithSinonAccessor<Request>' is not assignable to parameter of type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.
Type 'StubbedInstanceWithSinonAccessor<Request>' is missing the following properties from type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>': get, header, accepts, acceptsCharsets, and 68 more.ts(2345)
【问题讨论】:
标签: unit-testing request mocking loopback4