首页 > 解决方案 > ts-mocha 和 chai - 错误 TS2695:逗号运算符的左侧未使用且没有副作用

问题描述

工具/库版本:

"ts-mocha": "^8.0.0",
"ts-node": "^10.3.0",
"chai": "^4.3.4",

代码:

expect(wrapper.find(MyListItem)).to.have.length(3);

命令:

ts-mocha tests/**/*.tsx  -r unitTestSetup.ts

我的打字稿编译器选项:

{
"compilerOptions": {
  "target": "es5",
  "module": "commonjs",
  "declaration": true,
  "outDir": "./lib",
  "strict": true,
  "esModuleInterop": true,
},

错误:

tests/index.spec.tsx:41:10 - error TS2695: Left side of comma operator is unused and has no side effects.
41         (0, chai_1.expect)(wrapper.find(MyListItem)).to.have.length(3); 

这似乎是由于未安装 ts-mocha 的可选依赖项造成的。( tsconfig-paths)

npm install --force有没有比在 ts-mocha 包上强制安装 tsconfig-paths更好的方法来解决这个问题?(我提供的答案)

标签: reactjstypescriptmocha.jschai

解决方案


我通过在我的package.json文件中创建一个“fix-ts-mocha”脚本来解决这个问题:

"fix-ts-mocha": "cd node_modules && cd ts-mocha && npm install --force"

我之后运行一次npm install(或每次ts-mocha更新)。


推荐阅读