reactjs - 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更好的方法来解决这个问题?(我提供的答案)
解决方案
我通过在我的package.json
文件中创建一个“fix-ts-mocha”脚本来解决这个问题:
"fix-ts-mocha": "cd node_modules && cd ts-mocha && npm install --force"
我之后运行一次npm install
(或每次ts-mocha
更新)。
推荐阅读
- html - 使用智能手机摄像头从网页扫描条码
- javascript - 由于“不变违规:未找到名称输入的视图配置”,无法为 React Native 工作获得 Reactable
- java - Files.createDirectories() 抛出 FileAlreadyExistsExceptions 但没有目录
- git - 保持特定的 git 分支离线
- python - 无法在 Pycharm 中导入 numpy 或 matplotlib
- google-app-engine - 将 ext-stackdriver_debugger 添加到 composer 以在 Google App Engine 中启用 StackDriver 调试
- javascript - Javascript 粘性菜单 - 控制台错误
- c - 如何仅用一个 Ctrl+d 结束输入
- c# - .NET Treeview NodeMouseClick 事件有滞后?
- c++ - 构造对象的歧义