I am using mocha "mocha": "^7.2.0" to do a unit test in typescript project, when I add expect statement in mocha unit test like this:
expect(4 + 5).to.be.equal(9);
and run the unit test using yarn test, show error:
~/source/reddwarf/frontend/js-wheel on main! ⌚ 16:06:47
$ yarn test ‹ruby-2.7.2›
yarn run v1.21.1
$ mocha --recursive --require babel-register test/**/** test/utils/data/** --bail
TSError: ⨯ Unable to compile TypeScript:
test/utils/data/DeviceHandler.test.ts:11:10 - error TS2695: Left side of comma operator is unused and has no side effects.
11 (0, _chai.expect)(4 + 5).to.be.equal(9);
~
at createTSError (/Users/dolphin/source/reddwarf/frontend/js-wheel/node_modules/ts-node/src/index.ts:840:12)
at reportTSError (/Users/dolphin/source/reddwarf/frontend/js-wheel/node_modules/ts-node/src/index.ts:844:19)
at getOutput (/Users/dolphin/source/reddwarf/frontend/js-wheel/node_modules/ts-node/src/index.ts:1034:36)
at Object.compile (/Users/dolphin/source/reddwarf/frontend/js-wheel/node_modules/ts-node/src/index.ts:1342:43)
at Module.m._compile (/Users/dolphin/source/reddwarf/frontend/js-wheel/node_modules/ts-node/src/index.ts:1474:30)
at loader (/Users/dolphin/source/reddwarf/frontend/js-wheel/node_modules/babel-register/lib/node.js:144:5)
at require.extensions.<computed> (/Users/dolphin/source/reddwarf/frontend/js-wheel/node_modules/babel-register/lib/node.js:154:7)
at Object.require.extensions.<computed> [as .ts] (/Users/dolphin/source/reddwarf/frontend/js-wheel/node_modules/ts-node/src/index.ts:1478:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at requireOrImport (/Users/dolphin/source/reddwarf/frontend/js-wheel/node_modules/mocha/lib/esm-utils.js:15:12)
at Object.exports.loadFilesAsync (/Users/dolphin/source/reddwarf/frontend/js-wheel/node_modules/mocha/lib/esm-utils.js:28:26)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async singleRun (/Users/dolphin/source/reddwarf/frontend/js-wheel/node_modules/mocha/lib/cli/run-helpers.js:149:3)
at async exports.runMocha (/Users/dolphin/source/reddwarf/frontend/js-wheel/node_modules/mocha/lib/cli/run-helpers.js:186:5)
at async Object.exports.handler (/Users/dolphin/source/reddwarf/frontend/js-wheel/node_modules/mocha/lib/cli/run.js:319:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
(base)
why did this happen? what should I do to fix this problem? This is the full test code:
import 'mocha'
import { expect } from 'chai'
describe('testFunc test', function () {
it('incre', function () {
expect(4 + 5).to.be.equal(9);
})
})