1

是否可以在打字稿中使用ts-mockito模拟来自Express的类请求?

我尝试了以下

import { Request, Response } from "express";  

const request = mock(Request);
const req: Request = instance(request);

但在说明时出现错误reqType 'Request' is missing the following properties from type 'Request<ParamsDictionary>': get, header, accepts, acceptsCharsets, and 73 more.

4

1 回答 1

3

Request 是一个接口,因此您应该使用以下语法:

import { Request, Response } from "express";
import { mock, instance } from "ts-mockito";

const mockReq = mock<Request>();
const req = instance(mockReq);

有关更多信息,请参阅ts-mockito 文档

于 2020-09-01T16:07:12.320 回答