簡體   English   中英

如何在async.series中使用Mocha測試

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

我正在嘗試使用async.series來控制流異步Mocha測試,但是,似乎從未執行過callback(),因為它僅執行第一個測試,並且從不在結束回調中輸出日志消息。 似乎在外部測試中調用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

您正在使用異步測試,而從未調用過回調。 如果您確實需要同步測試,則可以僅同步使用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