[英]using assert with ts-node in mocha test
I created a mocha
test in a test.ts
我在
test.ts
创建了一个mocha
测试
import * as assert from "assert";
describe('it', () => {
it('should ', done => {
assert.strictEqual(true, false);
done();
});
});
My package.json
s devDependencies
: 我的
package.json
的devDependencies
:
"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
: tsconfig.json
:
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"sourceMap": true,
"declaration": true,
"outDir": "./dist",
"strict": true,
"types": ["mocha"]
}
}
When running ts-node
, I get this error: 运行
ts-node
,出现此错误:
error TS2307: Cannot find module 'assert'.
My commandline call is this: 我的命令行调用是这样的:
./node_modules/mocha/bin/mocha -r ts-node/register test/test.ts
Regular tsc
throws no errors. 常规的
tsc
不会引发任何错误。
Solved it via this issue comment on GitHub: 通过此问题在GitHub上的注释解决了它:
types
in tsconfig.json
needs to include node
: tsconfig.json
types
需要包含node
:
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"sourceMap": true,
"declaration": true,
"outDir": "./dist",
"strict": true,
"types": ["mocha", "node"]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.