I am currently working on developing a straightforward API using Express, and I have encountered an issue while attempting to add tests with Jest. When running the tests, an error is displayed:
ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.
at BufferList.Readable (node_modules/readable-stream/lib/_stream_readable.js:179:22)
at BufferList.Duplex (node_modules/readable-stream/lib/_stream_duplex.js:67:12)
at new BufferList (node_modules/bl/bl.js:33:16)
at new MessageStream (node_modules/mongodb/lib/cmap/message_stream.js:35:21)
at new Connection (node_modules/mongodb/lib/cmap/connection.js:52:28)
/home/jonathangomz/Documents/Node/Express/Devotionals/node_modules/readable-stream/lib/_stream_readable.js:111
var isDuplex = stream instanceof Duplex;
^
TypeError: Right-hand side of 'instanceof' is not callable
Concerns arise regarding the reliability of the test results right after Jest encounters this issue:
https://i.sstatic.net/87bam.pngThe test script is as follows:
const app = require("../app");
const request = require("supertest");
describe("Testing root router", () => {
test("Should test that true === true", async () => {
jest.useFakeTimers();
const response = await request(app).get("/");
expect(response.status).toBe(200);
});
});
The Jest configuration in my package.json
file is set as:
"jest": {
"testEnvironment": "node",
"coveragePathIgnorePatterns": [
"/node_modules/"
]
}
Additional Notes:
Despite attempting to use jest.useFakeTimers()
, the issue persists and it seems like I may be implementing it incorrectly. I have also tried adding it within the beforeEach
method without success.