【问题标题】:More than one test fails due to import after jest is torn down - Supertest Typescript and Express API在 jest 被拆除后,由于导入导致不止一项测试失败 - Supertest Typescript 和 Express API
【发布时间】:2022-01-25 19:07:39
【问题描述】:

我遇到了使用supertestjest 运行多个测试的问题。当只有一个测试运行时,它可以正常工作,但第二个会引发以下错误:

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.

我用两个非常简单的测试对此进行了测试:

describe("Default API", () => {
    describe("Default:", () => {
        it("should create a user in the DB", (done) => {
            request(app).get("/").expect(200, done);
        });
        it("should create a user in the DB", (done) => {
            request(app).get("/").expect(200, done);
        });
    });
});

它们是相同的,但第二个会引发错误。如果我只运行第一个没有问题。这一定是设置问题有没有人有建议。在我有主要快递代码的 index.ts 中,我导出应用程序如下:

export default app;

这是 index.ts 文件的底部。

【问题讨论】:

    标签: express jestjs supertest


    【解决方案1】:

    我遇到了类似的问题并关闭了问题,在我的情况下,我想使用 mysql2 来访问 mariadb。该模块尝试自动检测字符集并尝试加载该编码。

    但我暂时还没有找到解决方案。

    【讨论】:

      猜你喜欢
      • 2021-08-15
      • 2020-05-11
      • 2020-12-27
      • 1970-01-01
      • 1970-01-01
      • 2020-11-26
      • 2018-04-03
      • 2019-03-17
      • 2013-09-26
      相关资源
      最近更新 更多