forwardemail / forwardemail/supertest

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

Open
#712 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.4k
Forks
782
PR merge metrics
No merged PRs in 30d

Description

I'm using supertest to test api route in a node/typescript application. When launching the test, the server crashes with this error:

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

Here is the test:

```js
import request from "supertest";
import { server } from "../index";

describe("GET /user/:id", () => {
it("return user information", (done) => {
request(server)
.get("/user/123")
.set("Cookie", ["_id=567;locale=en"])
.expect(200, done);
});
});
```

The jest config (which has a linter error by the way: `'module' is not defined.`):

```js
module.exports = {
roots: ["/src"],
testMatch: [
"**/__tests__/**/*.+(ts|tsx|js)",
"**/?(*.)+(spec|test).+(ts|tsx|js)",
],
transform: {
"^.+\\.(ts|tsx)$": "ts-jest",
},
testEnvironment: "node",
};
```

The script line in package.json:
```js
"test": "jest --runInBand",
```

How to fix this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.