I use pactum and jest for e2e testing
but while testing the endpoint which sets cookies, nest throws an error
[Nest] 3364 - 01/03/2023, 5:35:15 PM ERROR [ExceptionsHandler] response.setCookie is not a function
TypeError: response.setCookie is not a function
But how to register cookie middleware for testing module??
app.e2e-spec.ts
let app: INestApplication
beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
imports: [AppModule],
}).compile()
app = moduleRef.createNestApplication<NestFastifyApplication>(
new FastifyAdapter(),
)
app.useGlobalPipes(new ValidationPipe())
await app.init()
await app.getHttpAdapter().getInstance().ready()
await app.listen(3333)
})
afterAll(() => {
app.close()
})
Just like you register it in your
main.ts
. You need to callapp.register()
to register the middleware before you callapp.listen()