Search code examples
node.jstypescriptjestjsnestjs

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


I have tried to add cookie-parser - https://www.npmjs.com/package/cookie-parser to my NestJS app:

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

When running as normal (compile and run js) NO error is occur and code works as expected, but when trying to run e2e tests (using Jest, Supertest) on the same code the following error is occur during boot: TypeError: cookieParser is not a function

Also, when using cookieParser instead of cookieParser(), above-mentioned error isn't occur, but code doesn't work as expected.

During e2e tests, I'm using Test.createTestingModule and then moduleFixture.createNestApplication().

Do you have any idea what wrong here? Thank you.


Solution

  • Change the import to:

    import cookieParser from 'cookie-parser';