伙计们,我正在关注这个Link,以学习如何在TypeScript中进行单元测试。 完全遵循该规则,但是运行npm test会产生此错误:
我的代码如下:
----普通构造函数----
export class Cliente {
payment_method: String;
constructor(payment_method: String) {
this.payment_method = payment_method;
}
}
----测试----
import { expect } from 'chai';
import { Cliente } from '../src/client';
let payment_method: String = 'paypal';
it('constructorTest', () => {
let clientObj = new Cliente(payment_method);
expect(clientObj.payment_method).to.be('paypal');
})
---- TS Config和Package.json ----
{
"compilerOptions": {
"module": "commonjs",
"sourceMap": true,
"target": "es2015"
}
}
{
"name": "testTS",
"type": "module",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "cross-env TS_NODE_FILES=true mocha — exit — require ts-node/register — colors test/**/*.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/chai": "^4.2.7",
"@types/mocha": "^5.2.7",
"@types/node": "^12.12.18",
"chai": "^4.2.0",
"cross-env": "^5.2.0",
"mocha": "^6.2.0",
"nyc": "^14.1.1",
"ts-node": "^8.3.0",
"typescript": "^3.5.3"
}
}
我已经尝试了一些解决方案,但是没有任何解决方案。我可能忽略了它,似乎无法解决它!
不胜感激。