I have a test suite in plain JS and a project which is only somewhat migrated to TS.
My tests works fine with regular mocha using the transpiled JS, but when using ts-mocha on the mixed js/ts code I get some difference in behaviour. Mainly, the context of the before/after functions is undefined.
Example:
before(async() => {
// some setup code that uses the mocha test context through "this"
}
...
describe( ... )
When this is run with ts-mocha, this is undefined in before, after etc, with plain mocha this is set to the test context object.
Am I doing something wrong or does ts-mocha not have equivalent semantics as mocha?
EDIT: I found that arrow functions are discouraged in mocha: https://mochajs.org/#arrow-functions and that changing to function solves the issue! However, the same code works in mocha but not in ts-mocha, so there's still a discrepancy?
I have a test suite in plain JS and a project which is only somewhat migrated to TS. My tests works fine with regular
mocha
using the transpiled JS, but when usingts-mocha
on the mixed js/ts code I get some difference in behaviour. Mainly, the context of thebefore
/after
functions isundefined
.Example:
When this is run with
ts-mocha
,this
is undefined inbefore
,after
etc, with plainmocha
this is set to the test context object. Am I doing something wrong or doests-mocha
not have equivalent semantics asmocha
?EDIT: I found that arrow functions are discouraged in
mocha
: https://mochajs.org/#arrow-functions and that changing tofunction
solves the issue! However, the same code works inmocha
but not ints-mocha
, so there's still a discrepancy?