WebStorm not recognising Mocha describe() and it()

2019-02-16 10:25发布

This question already has an answer here:

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-definatelyTyped library downloaded, and added to the tests folder.

Scopes

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

2条回答
ら.Afraid
2楼-- · 2019-02-16 10:33

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 mocha-DefinitelyTyped library is in the list (don't select it). If it is not in the list, click the Download... button, find it there, and add it. Then click the Manage Scopes... button, find your test directory, click on the library column, and select the mocha-DefinitelyTyped entry. See the screenshot below.Screenshot of the referenced preferences page

查看更多
爷、活的狠高调
3楼-- · 2019-02-16 10:51

This answer might help you: Mocha's describe "require() is missing" in WebStorm 11. It explains how to disable specific inspections for specific folders, which can be useful when working with Mocha. So it is a different approach to installing the mocha-definatelyTyped library.

查看更多
登录 后发表回答