Async function in mocha before() is alway finished before it() spec?

后端 未结 2 1968
无人及你
无人及你 2020-11-28 06:35

I have a callback function in before() which is for cleaning database. Is everything in before() guaranteed to finish before it() sta

2条回答
  •  感情败类
    2020-11-28 06:54

    Hopefully your db.collection() should return a promise. If yes then you can also use async keyword in before()

    // Note: I am using Mocha 5.2.0.
    before(async function(){
       await db.collection('user').remove({}, function(res){}); // it is now guaranteed to finish before it()
    });
    

提交回复
热议问题