Mocha has a built-in callback done to make this happen. The model I use for my code is:
describe('some spec', function () { beforeEach(function (done) { // common spec initalization code.. common.init (function (err, stuff) { done(err); }); }); describe('particular case', function () { var result, another; beforeEach(function (done) { // case init 1.. case.init(function (err, res) { result = res; done(err); }); }); beforeEach(function (done) { // case init 2.. case.init2(function (err, res) { another = res; done(err); }); }); it ('should be smth', function () { expect(result).to.equal(0); }); it ('should be smth else', function () { expect(another).to.equal(1); }); }); });
source share