Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebStorm not recognising Mocha describe() and it() [duplicate]

Tags:

I admit that I'm being pedantic here. I have a Mocha test in WebStorm and WebStorm is complaining about describe() and it() not being a function type.

Method expression is not of Function type

I have the mocha-definitelyTyped library downloaded, and added to the tests folder.

Scopes

Running Mocha is fine. Why is WebStorm not resolving the describe and it methods?

like image 432
BanksySan Avatar asked Oct 05 '15 19:10

BanksySan


People also ask

How do I run a mocha test in Webstorm?

Create a Mocha run configurationin the left-hand pane, and select Mocha from the list. The Run/Debug Configuration: Mocha dialog opens. Specify the Node interpreter to use and the location of the mocha package. Specify the working directory of the application.

How do I run a single test file in mocha?

If you just want to run one test from your entire list of test cases then, you can write only ahead of your test case. If you want to run all the test cases which are inside one describe section, then you can also write only to describe as well. describe.


1 Answers

From the description of the inspection:

When using libraries that define their own global symbols outside their visible JavaScript code (e.g. describe() in Mocha), it is recommended that you add the corresponding TypeScript type definition file as a JavaScript library in Preferences | Languages & Frameworks | JavaScript | Libraries.

Navigate to the above referenced preference and make sure the @types/mocha (this was changed in early 2019 from mocha-DefinitelyTyped. Either is OK.) library is in the list (don't select it). If it is not in the list, click the Download... button, find mocha there, and add it. Then click the Manage Scopes... button, find your test directory, click on the library column, and select the @types/mocha entry. See the screenshot below.Screenshot of the referenced preferences page

like image 86
BamaPookie Avatar answered Oct 09 '22 08:10

BamaPookie