Making mocha "use strict" when running in node

Problem

Is there a way to make Mocha run tests in strict mode when running on node?

Normally you can enable this in node by running node --use_strict. Is there a way to do the same thing for mocha?

Problem courtesy of: Matt Zukowski

Solution

Add --use_strict to the mocha command.

So your command might look like this :

mocha ./test --recursive --use_strict
Solution courtesy of: Edd

Discussion

I would just start test scripts with 'use strict';

Discussion courtesy of: jndvdcn

There is no way to pass --use_strict into mocha and this was done in purpose. Read the discussion for details.

If you really want this behaviour you could fork mocha's sources or load this npm module as a first thing in your tests.

Discussion courtesy of: Yevgen Safronov

This recipe can be found in it's original form on Stack Over Flow.