Mocha provides before
, beforeEach
, after
and afterEach
. I am looking for something like around
or aroundEach
, but I can not find anything in the mocha docs about this.
My use case is that I would like to wrap each test in a database transaction, performing a rollback after each of them starts. I suppose to do something like this:
aroundEach(function (testRunner, done) { sequelize.transaction().next(function (t) { testRunner(); t.rollback().done(done); }); });
As an alternative / workaround, something like this exists as an option (although it feels less clean):
beforeEach(function (done) { sequelize.transaction().next(function (t) { this.transaction = t; done(); }.bind(this)); }); afterEach(function (done) { this.transaction.rollback().done(done); });
source share