I'm using supertest to test api route in a node/typescript application. 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:
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: 'module' is not defined.
)
module.exports = {
roots: ["<rootDir>/src"],
testMatch: [
"**/__tests__/**/*.+(ts|tsx|js)",
"**/?(*.)+(spec|test).+(ts|tsx|js)",
],
transform: {
"^.+\\.(ts|tsx)$": "ts-jest",
},
testEnvironment: "node",
};
How to fix this?