Jon*_*rez 8 javascript express jestjs
我正在使用 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
Run Code Online (Sandbox Code Playgroud)
我的测试是:
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);
});
});
Run Code Online (Sandbox Code Playgroud)
我的笑话配置package.json:
"jest": {
"testEnvironment": "node",
"coveragePathIgnorePatterns": [
"/node_modules/"
]
}
Run Code Online (Sandbox Code Playgroud)
我读过,jest.useFakeTimers()但它不起作用,我不确定我是否使用了错误的方式。我也尝试将其添加到该beforeEach方法中,但没有任何结果。
小智 -2
尝试--testTimeout=10000在调用 jest 时添加标志,这对我有用。
基于使用 Jest 和 Supertest 测试 NodeJs/Express API的信息
--testTimeout 标志 - 这会增加 Jest 的默认超时,即 5000 毫秒。这很重要,因为测试运行者需要在运行测试之前刷新数据库
| 归档时间: |
|
| 查看次数: |
21872 次 |
| 最近记录: |