Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Fixed async hook arity check

Tj Holowaychuk007838306186
diff --git a/lib/runner.js b/lib/runner.js
index a7c64bf8..2ff0a064 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -71,7 +71,7 @@ Runner.prototype.hook = function(name, fn){
if (!callback) return fn();
// async
- if (2 == callback.length) {
+ if (1 == callback.length) {
// async
try {
callback(function(err){
diff --git a/test/unit/hook.async.js b/test/unit/hook.async.js
index db6301a6..100a2ccf 100644
--- a/test/unit/hook.async.js
+++ b/test/unit/hook.async.js
@@ -1,73 +1,82 @@
describe('async', function(){
var calls = [];
-
+
process.on('exit', function(){
calls.should.eql([
'before all'
- , 'before one'
- , 'after one'
- , 'before two'
- , 'after two'
- , 'before three'
- , 'after three'
+ , 'before'
+ , 'one'
+ , 'after'
+ , 'before'
+ , 'two'
+ , 'after'
+ , 'before'
+ , 'three'
+ , 'after'
, 'after all']);
})
-
+
beforeEach(function(){
// not hit
calls.push('parent before');
})
-
+
afterEach(function(){
// not hit
calls.push('parent after' );
})
-
+
describe('beforeEach()', function(){
before(function(){
calls.push('before all');
});
-
+
after(function(){
calls.push('after all');
});
-
+
beforeEach(function(done){
process.nextTick(function(){
- calls.push('before ' + test.title);
+ calls.push('before');
done();
})
})
-
+
it('one', function(done){
calls.should.eql([
'before all'
- , 'before one']);
+ , 'before']);
+ calls.push('one');
process.nextTick(done);
})
it('two', function(){
calls.should.eql([
'before all'
- , 'before one'
- , 'after one'
- , 'before two']);
+ , 'before'
+ , 'one'
+ , 'after'
+ , 'before']);
+ calls.push('two');
})
it('three', function(){
calls.should.eql([
'before all'
- , 'before one'
- , 'after one'
- , 'before two'
- , 'after two'
- , 'before three']);
+ , 'before'
+ , 'one'
+ , 'after'
+ , 'before'
+ , 'two'
+ , 'after'
+ , 'before']);
+ calls.push('three');
})
-
+
afterEach(function(done){
process.nextTick(function(){
- calls.push('after ' + test.title);
+ calls.push('after');
done();
})
})