Nestjs 测试 e2e ECONNREFUSED 127.0.0.1:80

Bab*_*boo 11 e2e-testing nestjs

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

这是我的代码:

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 ...`, () => {
      //...
    });
  });
});
Run Code Online (Sandbox Code Playgroud)

Bab*_*boo 22

修复方法非常简单,但很难找到。感谢这个线程,这就是我所做的:

const TEST_URL = '/test';
                  ^ add a '/'
Run Code Online (Sandbox Code Playgroud)

  • 谢谢。我要花很长时间才能弄清楚! (2认同)