Nestjs 测试 e2e ECONNREFUSED 127.0.0.1:80

Nestjs test e2e ECONNREFUSED 127.0.0.1:80

当 运行 使用 Nestjs 测试 e2e 来测试 dto 时,我遇到错误 ECONNREFUSED 127.0.0.1:80

这是我的代码:

const TEST_URL = 'test';

@Controller(TEST_URL)
class TestController {
  @Post()
  public test(@Body() param: TimeTableParam) {
    // nothing
  }
}

describe('TimeTableParam', () => {
  let app: INestApplication;

  beforeAll(async () => {
    const module: TestingModule = await Test.createTestingModule({
      controllers: [TestController],
    }).compile();

    app = module.createNestApplication();
    await app.init();
  });

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

  describe('...', () => {
    it(`should ...`, () => {
      //...
    });
  });
});

修复非常简单但很难找到。感谢这个 thread 这就是我所做的:

const TEST_URL = '/test';
                  ^ add a '/'