【问题标题】:Getting error when running a test : TS6196 is declared but never used运行测试时出错:声明了 TS6196 但从未使用过
【发布时间】:2023-01-27 16:37:47
【问题描述】:

尝试按照本指南 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/hello-world-service.unit.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);
    }
}

【问题讨论】:

    标签: javascript mocha.js eslint typescript-eslint


    【解决方案1】:

    尝试在你的tsconfig.json中关闭你的noUnusedLocals选项

    here 相同的问题

    【讨论】:

      猜你喜欢
      • 2019-10-16
      • 2014-03-12
      • 2017-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-05
      • 2017-12-04
      • 1970-01-01
      相关资源
      最近更新 更多