简体   繁体   English

如何在async.series中使用Mocha测试

[英]How to use mocha tests with async.series

I'm trying to use async.series to control flow asynchronous mocha tests like this but the callback() doesn't seem to ever be executed as it only does the first test and never outputs the log message in the end callback. 我正在尝试使用async.series来控制流异步Mocha测试,但是,似乎从未执行过callback(),因为它仅执行第一个测试,并且从不在结束回调中输出日志消息。 It seems as if after done() is called in the external test it returns back to execute the console.log correctly, but maybe it just recognize what callback references?: 似乎在外部测试中调用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');
    });
});

Output is: 输出为:

<mocha test result for test 1>
1

You are using asynchronous tests without ever calling the callbacks. 您正在使用异步测试,而从未调用过回调。 If you really need to synchronize your tests, you could just use Mocha synchronously (without callbacks) 如果您确实需要同步测试,则可以仅同步使用Mocha(无需回调)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM