Skip to content Skip to sidebar Skip to footer

Running Mocha On The Command Line And Including A File

I’m trying to setup some JS Unit tests using Mocha, and Ideally, I'd like to run this via the command line oppose to a web page. (TL:DR; at the bottom) First I did some bullshit

Solution 1:

The only thing missing is making a reference to the Cow export from the require().

You'll just have to change this line:

require( "../src/cow.js" );

To this:

varCow = require( "../src/cow.js" ).Cow;

Solution 2:

You can always specify files at runtime

-r, --require <name>            require the given module

mocha -r ../src/cow.js  yourcode.js

Post a Comment for "Running Mocha On The Command Line And Including A File"