如何使用async.series进行mocha测试

时间:2014-03-18 16:06:22

标签: javascript node.js asynchronous mocha

我试图使用async.series来控制像这样的流异步mocha测试,但回调()似乎没有被执行,因为它只执行第一次测试并且从不输出日志消息最后的回调。似乎在外部测试中调用done()之后它返回正确执行console.log,但它可能只是识别callback引用了什么?:

describe('auth test' ,function(){

    async.series([
        function(callback){
            //TEST: login user : POST bad login
            it('1'), function(done){
               test1(done, 'path',  function(rdy){  //this test is in a separate module
                    console.log(1);
                    callback(null);
                });
            });
        },
        function(callback){
            it('2'), function(done){
               test2(done, 'path',  function(rdy){    //this test is in a separate module
                    console.log(2);
                    callback(null);
                });
            });
        }
    ],
     function(err){
        console.log('tests done');
    });
});

输出是:

<mocha test result for test 1>
1

1 个答案:

答案 0 :(得分:0)

您正在使用异步测试,而无需调用回调。如果你真的需要同步你的测试,你可以同步使用Mocha(没有回调)

it ('1', function() {
  test1('path',  function(rdy) {
    console.log(1);
    callback();
  });
});
相关问题