{ it('should ', -6ren">
gpt4 book ai didi

node.js - 在 mocha 测试中使用带有 ts-node 的断言

转载 作者:行者123 更新时间:2023-12-05 02:14:02 29 4
gpt4 key购买 nike

我在 test.ts 中创建了一个 mocha 测试

import * as assert from "assert";

describe('it', () => {
it('should ', done => {
assert.strictEqual(true, false);
done();
});
});

我的package.jsondevDependencies:

"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/node": "^10.12.18",
"mocha": "^5.2.0",
"ts-node": "^8.0.1",
"typescript": "^3.2.4"
}

tsconfig.json:

{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"sourceMap": true,
"declaration": true,
"outDir": "./dist",
"strict": true,
"types": ["mocha"]
}
}

当运行 ts-node 时,我得到这个错误:

错误 TS2307:找不到模块“断言”。

我的命令行调用是这样的:

./node_modules/mocha/bin/mocha -r ts-node/register test/test.ts

常规 tsc 不会抛出任何错误。

最佳答案

通过 this issue comment 解决了它在 GitHub 上:

tsconfig.json 中的 types 需要包含 node:

{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"sourceMap": true,
"declaration": true,
"outDir": "./dist",
"strict": true,
"types": ["mocha", "node"]
}
}

关于node.js - 在 mocha 测试中使用带有 ts-node 的断言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54375083/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com