NestJS cookie-parser 不是 e2e 测试期间的函数错误

NestJS cookie-parser is not a function error during e2e test

我已尝试将 cookie-parser - https://www.npmjs.com/package/cookie-parser 添加到我的 NestJS 应用程序:

import * as cookieParser from 'cookie-parser';
consumer
.apply(cookieParser())
.forRoutes('/');

当 运行ning 正常时(编译和 运行 js)没有错误发生并且代码按预期工作,但是 当尝试对同一代码进行 运行 端到端测试(使用 Jest、Supertest)时,在启动过程中出现以下错误: TypeError: cookieParser is not a function

此外,当使用 cookieParser 而不是 cookieParser() 时,不会出现上述错误,但代码无法按预期运行。

在 e2e 测试期间,我使用 Test.createTestingModule 然后 moduleFixture.createNestApplication()

你知道这里出了什么问题吗?谢谢。

将导入更改为:

import cookieParser from 'cookie-parser';