Global `before` and `beforeEach` for mocha?

Freewind picture Freewind · May 12, 2012 · Viewed 53.3k times · Source

I'm using mocha for javascript unit-testing now.

I have several test files, each file has a before and beforeEach, but they are exactly the same.

How do I provide a global before and beforeEach for all of them (or some of them)?

Answer

AJcodez picture AJcodez · Dec 26, 2013

In the root of the test folder, create a global test helper test/helper.js which has your before and beforeEach

// globals
global.assert = require('assert');

// setup
before();
beforeEach();

// teardown
after();
afterEach();