Tool/Lib Versions:
"ts-mocha": "^8.0.0",
"ts-node": "^10.3.0",
"chai": "^4.3.4",
Code:
expect(wrapper.find(MyListItem)).to.have.length(3);
Command:
ts-mocha tests/**/*.tsx -r unitTestSetup.ts
My typescript compiler options:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"outDir": "./lib",
"strict": true,
"esModuleInterop": true,
},
Error:
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);
This seems to be caused by if an optional dependency for ts-mocha is not installed. ( tsconfig-paths
)
Is there a better way to fix this than doing a npm install --force
on the ts-mocha package to force it to install tsconfig-paths? (the answer I provided)
I fixed this by creating a 'fix-ts-mocha' script in my package.json
file:
"fix-ts-mocha": "cd node_modules && cd ts-mocha && npm install --force"
I run this once after npm install
(or each time ts-mocha
is updated).
I ran into the same issue with plain mocha, using ts-node. The reason was code infection by an ES module package. See also here .
Some people try to switch to ES modules like here but this didn't work for me as I still had mostly commonjs modules.
My solution was to get rid of the npm package using the ES module (ie having "type": "module"
in package.json
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.