简体   繁体   English

在Mocha测试中使用带有ts-node的assert

[英]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.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 : 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM