Nestjs测试e2e ECONNREFUSED 127.0.0.1:80

时间:2020-11-12 01:32:23

标签: nestjs e2e-testing

在使用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 ...`, () => {
      //...
    });
  });
});

1 个答案:

答案 0 :(得分:1)

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

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