Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've just installed WebStorm 11 and created a new project, however WebStorm is saying that a require() is needed for the describe method:

require() call is missing

I've added the definitely-types mocha library and the scope is for the test directory (which this file is in).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
302 views
Welcome To Ask or Share your Answers For Others

1 Answer

Edit: As noted in the comments, the actual issue addressed in this question is actually a bug in IntelliJ 15 / WebStorm 11 (see https://youtrack.jetbrains.com/issue/WEB-18768). I'm leaving the answer below because many people come here when searching for the solution provided.

The accepted answer is a sledgehammer approach to solving the problem. A better solution is to enable the mocha-DefinitelyTyped library for the test directory. Not only will this remove the erroneous inspection, it will provide better syntax highlighting.

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 preference section referenced above, ‘Preferences | Languages & Frameworks | JavaScript | Libraries’, and check if the mocha-DefinitelyTyped library is in the list.

If @types/mocha (used to be named mocha-DefinitelyTyped) is not in the list, click the Download… button, find ‘mocha’ in the ‘TypeScript community stubs’ section, select it, and click Download and Install:

‘mocha’ library to import, shown in the Download Library window

The library is named just mocha in the list, but will convert into @types/mocha (prior to early 2019, it would convert to mocha-DefinitelyTyped) once imported.

Once you have mocha-DefinitelyTyped, uncheck its Enabled checkbox. Leaving it fully checked would enable it globally, even outside of tests, which would be inaccurate. Instead, we will manage its scope to be enabled only in your test directory. 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 JavaScript Libraries Usage Scopes preferences window


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...