Permalink
Browse files

Store _enhanced early enough

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...
1 parent d23f87b commit 7b4dcd47ddb9fbe860591d8918a4bb4302ed195f @Almad Almad committed Jul 9, 2012
Showing with 6 additions and 5 deletions.
  1. +1 −2 lib/mocha-hooks.js
  2. +5 −3 lib/sinon-mocha.js
View
@@ -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;
},
/**
View
@@ -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(){

0 comments on commit 7b4dcd4

Please sign in to comment.