Reputation: 18525
I am using empty node.js typescript project. When I add the Mocha Unit Test for type script, it shows me that it can't find some keywords ("describe", "it") as follows:
How should I resolve it?
Upvotes: 4
Views: 3491
Reputation: 21
As @Michael Braude said@Michael Braude said, import mocha's d.ts
file,
now we can simply do this;
Install mocha and mocha type define by
npm i -D mocha @types/mocha
Add this line in your *.test.ts
file
import 'mocha'
Upvotes: 2
Reputation: 6973
You'll need to add a d.ts file for Mocha so that the TypeScript compiler understands the library you're consuming. There are several ways to get this file:
tsd install mocha-node
from the command line.After you've grabbed the d.ts file, you need to add a /// <reference> tag to your unit test so that Visual Studio finds the d.ts file and can parse it. Something like this - /// <reference path="typings/mocha/mocha.d.ts"/>.
Hope that helps.
Upvotes: 4