Skip to content

Commit

Permalink
Store _enhanced early enough
Browse files Browse the repository at this point in the history
This way, enhance() can be called multiple times, which is useful
when it's done on top of module level.
Otherwise, wrapped method will call itself infinitely.
  • Loading branch information
Almad committed Jul 9, 2012
1 parent d23f87b commit 7b4dcd4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 1 addition & 2 deletions lib/mocha-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ MochaHooks = {
beforeEachHook.ctx = suite.ctx;
beforeEachHook.timeout(suite.timeout());
suite._beforeEach.unshift(beforeEachHook);

MochaHooks._enhanced = true;
}
return runSuite.apply(this, arguments);
};
MochaHooks._enhanced = true;
},

/**
Expand Down
8 changes: 5 additions & 3 deletions lib/sinon-mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ SinonMocha = {

enhance: function(sinon, mocha){
SinonMocha.sinon = sinon;
Hooks.enhance(mocha);
Hooks.beforeEach(SinonMocha.beforeEach);
Hooks.afterEach(SinonMocha.afterEach);
if (!Hooks._enhanced) {
Hooks.enhance(mocha);
Hooks.beforeEach(SinonMocha.beforeEach);
Hooks.afterEach(SinonMocha.afterEach);
}
},

beforeEach: function(){
Expand Down

0 comments on commit 7b4dcd4

Please sign in to comment.