【问题标题】:NestJS + Fastify e2e testing: Jest did not exit one second after the test run has completedNestJS + Fastify e2e 测试:测试运行完成后一秒 Jest 没有退出
【发布时间】:2021-11-20 06:35:04
【问题描述】:

在运行 NestJS+Fastify 应用程序的端到端测试时,我注意到以下警告:

Jest 在测试运行完成后一秒没有退出。

这通常意味着在您的测试中存在未停止的异步操作。考虑使用 --detectOpenHandles 运行 Jest 来解决此问题。

我的代码遵循文档:

添加--detectOpenHandles 选项时,我看到以下内容:

 FAIL  test/app.e2e-spec.ts
  AppController (e2e)
    ✕ /GET cats (975 ms)

  ● AppController (e2e) › /GET cats

    expect(received).toEqual(expected) // deep equality

    Expected: 200
    Received: 404

      23 |       })
      24 |       .then((result) => {
    > 25 |         expect(result.statusCode).toEqual(200);
         |                                   ^
      26 |         expect(result.payload).toEqual('API is running.');
      27 |       });
      28 |   });

      at app.e2e-spec.ts:25:35

那么问题出在哪里?

【问题讨论】:

    标签: jestjs nestjs e2e-testing fastify nestjs-fastify


    【解决方案1】:

    粘贴的示例不完整,应用程序必须手动关闭,就像在 Express 示例中一样:

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

    警告消失了。还创建了PR to improve NestJS' docs

    【讨论】:

      猜你喜欢
      • 2021-03-28
      • 2021-12-26
      • 2019-06-15
      • 2019-02-05
      • 2021-03-01
      • 1970-01-01
      • 2018-12-08
      • 2020-08-25
      • 2019-09-16
      相关资源
      最近更新 更多