Fix: make all functions as async

Feat: afterFn parsing
This commit is contained in:
2016-04-01 01:32:55 +05:30
parent b88e355241
commit 63822c5124
+8 -5
View File
@@ -7,6 +7,9 @@ var fs = require('fs');
function mkAsyncFn( fn ){ function mkAsyncFn( fn ){
if( fn.length ){
return fn;
}
return function( done ){ return function( done ){
setTimeout( function(){ setTimeout( function(){
fn(); fn();
@@ -18,10 +21,8 @@ function mkAsyncFn( fn ){
function ItBlock( description, fn ){ function ItBlock( description, fn ){
var isAsync = ( fn.length > 0 );
this.description = description; this.description = description;
this.fn = isAsync ? fn : mkAsyncFn( fn ); this.fn = mkAsyncFn( fn );
} }
@@ -84,11 +85,13 @@ SimpleMocha.prototype.it = function( description, fn ){
SimpleMocha.prototype.before = function( fn ){ SimpleMocha.prototype.before = function( fn ){
this.currentDescribeBlock.beforeFn = fn; this.currentDescribeBlock.beforeFn = mkAsyncFn( fn );
}; };
SimpleMocha.prototype.after = function(){}; SimpleMocha.prototype.after = function( fn ){
this.currentDescribeBlock.afterFn = mkAsyncFn( fn );
};
SimpleMocha.prototype.beforeEach = function(){}; SimpleMocha.prototype.beforeEach = function(){};
SimpleMocha.prototype.afterEach = function(){}; SimpleMocha.prototype.afterEach = function(){};