By default, when importing mocha
in TypeScript, it brings in describe
and it
(and some others) into the global namespace.
Is there a way to bring in specific imports like import {describe, it} from 'mocha'
?
By default, when importing mocha
in TypeScript, it brings in describe
and it
(and some others) into the global namespace.
Is there a way to bring in specific imports like import {describe, it} from 'mocha'
?
Since TypeScript 2.0, you can add
mocha
to thetypes
configuration of yourtsconfig.json
and it will always be loaded:I was having issues with errors and warnings, the problem stemmed from me renaming
tsconfig.json
to something else which makes Visual Studio Code enter "File Scope" instead of "Explicit Project". That made it impossible to importit
without a red squiggly. Now that I've renamed the config back totsconfig.json
thenimport 'mocha';
works as Eryk mentioned.https://code.visualstudio.com/Docs/languages/typescript
Install mocha and its types:
Then, simply import mocha in your test files: