0

I'm trying to run a unit test with Mocha using the below command in Windows.

mocha --require ts-node/register test.spec.ts

and getting the following error

error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.

This is despite having the following in my tsconfig.json file.

"experimentalDecorators": true,

Can anyone advise how I reference the tsconfig.json file?

David Hawkins
  • 1,049
  • 1
  • 10
  • 30
  • I have tried the command in different directories, including the one with the tsconfig but still get the same error. – David Hawkins Feb 25 '19 at 13:33
  • I have also tried `mocha --require ts-node/register --compilerOptions '{"experimentalDecorators": true}' test.spec.ts` but get the same error. – David Hawkins Feb 26 '19 at 09:53
  • If I run this directly from the directory that has my `tsconfig.json` then I get a different error `Unexpected token import`. – David Hawkins Feb 26 '19 at 10:26
  • I can get the test to run if I remove `"module": "es6",` from my tsconfig. However this breaks then my whole site. – David Hawkins Feb 26 '19 at 10:49

1 Answers1

0

In my package.json script, I set the path of my tsconfig.json file in the environment variable TS_NODE_PROJECT using cross-env:

By running something like this, you should be able to solve the decorator problem:

cross-env TS_NODE_PROJECT=<your-ts-config-json-file> mocha --require ts-node/register test.spec.ts
GioRetti
  • 56
  • 3