这是我的中间件:
export const isLogged = () => (req: Request, res: Response, next: NextFunction) => next();
我正在尝试创建一个单元测试,但是我无法使用正确的类型进行mock:
const middleware = middlewares.isLogged()
middleware(
jest.fn<Request>(), // Expected 0-2 type argument but got 1
jest.fn<Response>(),
jest.fn<NextFunction>(),
);
这不起作用,我尝试过模拟express
模块,但还没有让它工作。 我该如何模拟它们?
req.get()
函数? - Christopher Franciscoreq
和res
上模拟属性。 - Brian Adamsreq: any
就解决了问题。我之前没有尝试过这种方法,因为我的中间件本地参数已经被定义为req: Request
类型,但看起来它仍然可以正常工作。谢谢! - Christopher Francisco