Skip to content

Instantly share code, notes, and snippets.

@danshultz
Created May 7, 2012 19:00
Show Gist options
  • Save danshultz/2629698 to your computer and use it in GitHub Desktop.
Save danshultz/2629698 to your computer and use it in GitHub Desktop.
mocha.js -r --require and custom assertion libraries

Explaination

I have been using mocha for a little while with the "should" assertion library on the node side and chai in the web browser. I determined I wanted to use chai for my server side js testing as well but I didn't want to require chai explicitly at the top of each file so I looked at the --require parameter for mocha and determined that I could leverage this to setup my testing framework as well as any custom matchers/other framework uils

The command I now use to run mocha is mocha -r ./test/support/setup test/my_stuff.test.js

In doing this - you no longer have to explicitly register chai/sinon

Thoughts? Good idea/bad idea - gotchas that I'm unaware of thus far?

var chai = require('chai')
global.should = chai.should();
global.assert = chai.assert;
// Setup Sinon
global.sinon = require('sinon')
var sinonChai = require("sinon-chai");
chai.use(sinonChai);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment