BanksySan BanksySan - 29 days ago 20
Javascript Question

Mocha's describe "require() is missing" in WebStorm 11

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).

Answer

This is a new inspection introduced in v. 11 - it checks if the module used in code is referenced through require() statement. This inspection, indeed, is redundant for mocha tests ('describe' and other stuff don't need being required explicitly as they are added to global scope by Mocha). You can either disable this inspection or suppress it for 'describe', 'it', etc (see https://www.jetbrains.com/webstorm/help/suppressing-inspections.html). Another option: create a custom scope with your spec files excluded (Settings/Appearance & Behavior/Scopes), then choose this scope for 'Missing require() statement' inspection (Settings/Editor/Inspections/Javascript/Node.js).

Related ticket: WEB-18768