首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ts-mockito和Typescirpt模拟Express请求

使用ts-mockito和Typescirpt模拟Express请求
EN

Stack Overflow用户
提问于 2020-08-29 22:34:36
回答 1查看 370关注 0票数 1

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

我尝试了以下几种方法

代码语言:javascript
复制
import { Request, Response } from "express";  

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

但是在req上得到一个错误,声明:Type 'Request' is missing the following properties from type 'Request<ParamsDictionary>': get, header, accepts, acceptsCharsets, and 73 more.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-02 00:07:12

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

代码语言:javascript
复制
import { Request, Response } from "express";
import { mock, instance } from "ts-mockito";

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

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63648124

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档