error "You are trying to `import` a file after the Jest environment..." when testing nestjs e2e

120 views Asked by At

I want to write an e2e test for AuthController

import { AppModule } from '@/app.module'
import { INestApplication } from '@nestjs/common'
import { Test } from '@nestjs/testing'
import * as request from 'supertest'

describe('AuthController (e2e)', () => {
    let app: INestApplication

    beforeEach(async () => {
        const moduleFixture = await Test.createTestingModule({
            imports: [AppModule]
        }).compile()

        app = moduleFixture.createNestApplication()
        await app.init()
    })

    it('/auth/login (POST)', () => {
        return request(app.getHttpServer())
            .post('/auth/login')
            .send({
                email: '[email protected]',
                password: 'test'
            })
            .expect(201)
    })

    afterAll(async () => {
        await app.close()
    })
})

I enter the command yarn test:e2e and the error comes up "You are trying to import a file after the Jest environment has been torn down. From auth/auth.e2e-spec.ts" I use typeorm and postgres

0

There are 0 answers