尝试按照https://medium.com/swlh/how-to-setting-up-unit-tests-with-typescript-871c0f4f1609指南编写一个简单的测试,但在运行测试时得到TS6196: 'HelloWorldServiceUnitTests' is declared but never used.
错误。
./register.js
const tsNode = require('ts-node');
const testTSConfig = require('./test/tsconfig.json');
tsNode.register({
files: true,
transpileOnly: true,
project: './test/tsconfig.json'
});
./mocharc.json
{
"require": "./register.js",
"reporter": "dot"
}
./nycrc.json
{
"extends": "@istanbuljs/nyc-config-typescript",
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules/"
],
"extension": [
".ts"
],
"reporter": [
"text-summary",
"html"
],
"report-dir": "./coverage"
}
./test/您好-世界-服务.单元.test.ts
import {suite, test} from '@testdeck/mocha';
import * as _chai from 'chai';
_chai.should();
@suite
class HelloWorldServiceUnitTests {
// eslint-disable-next-line require-jsdoc
@test 'should do something when call a method'() {
const list = ['a', 'b', 'c'];
console.log(list);
}
}
运行测试时,在./test/tsconfig.json
中设置noUnusedLocals: false
仍会引发错误:
TSError: ⨯ Unable to compile TypeScript:
test/hello-world-service.unit.test.ts(7,7): error TS6196: 'HelloWorldServiceUnitTests' is declared but never used.
1条答案
按热度按时间iecba09b1#
尝试在
tsconfig.json
中关闭noUnusedLocals
选项与here的问题相同