【发布时间】:2021-04-04 06:38:07
【问题描述】:
我想为 Mocha 测试的根级挂钩设置超时。
我的根级钩子看起来像这样,在test/setup.ts:
import * as database from '../src/database/_db'
export const mochaHooks = {
/* Connect to the DB before running any tests */
beforeAll(done: () => void) {
database.initialize(done)
},
/* Close the DB connect after all tests finished */
afterAll(done: () => void) {
database.close(done);
}
};
这是通过--require test/setup.ts 加载的。数据库连接需要很长时间,所以我想增加超时值。
使用 -t 10000 运行 Mocha 可以,但也会为每个测试设置超时。
我也尝试在BeforeAll 中添加this.timeout(3000),但得到了✖ ERROR: test/setup.ts:10:14 - error TS2339: Property 'timeout' does not exist on type '{ beforeAll(done: () => void): void; afterAll(done: () => void): void; }'.
【问题讨论】:
标签: javascript node.js typescript mocha.js