【发布时间】:2020-12-27 08:48:53
【问题描述】:
我正在使用 Express 制作一个简单的 API,我正在尝试使用 Jest 添加测试,但是当我尝试运行测试时,它会显示下一个错误:
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
我的测试是:
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);
});
});
我在package.json上的笑话配置:
"jest": {
"testEnvironment": "node",
"coveragePathIgnorePatterns": [
"/node_modules/"
]
}
注意事项:
我阅读了有关 jest.useFakeTimers() 的信息,但它不起作用,我不确定我是否以错误的方式使用。我也尝试将它添加到 beforeEach 方法中,但没有。
【问题讨论】:
-
您好,您找到解决方案了吗?我遇到了和你一样的问题。
-
@DoneDeal0 no :c 这是一个学习项目,所以我暂停了测试部分,抱歉
标签: javascript api express jestjs