Nestjs 如何在e2e测试期间应用全局管道

Nestjs 如何在e2e测试期间应用全局管道,nestjs,Nestjs,使用Test.createTestingModule时如何应用全局管道 通常,当应用程序安装在main.ts中时,会添加全局管道 beforeEach(async done => { const moduleFixture: TestingModule = await Test.createTestingModule({ imports: [AppModule] }).compile() app = moduleFixture.createNestAp

使用
Test.createTestingModule
时如何应用全局管道

通常,当应用程序安装在
main.ts
中时,会添加全局管道

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

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

您可以在初始化测试模块之前添加它们:

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

    app = moduleFixture.createNestApplication()

    // Add global pipe here
    app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true, forbidNonWhitelisted: true }))

    await app.init()
    done()
  })

应该有一种方法可以自动包含main.ts中whats的类似内容