Не используйте done
при определении функции модульного теста async
, просто просто верните, как обычно, из асинхронного метода, после await
запроса от chai-http
:
it('Get Organizations', async function () {
let user_permission = await commonService.getuserPermission(logged_in_user_id,'organizations','findAll');
let api_status = 404;
if(user_permission) {
api_status = 200;
}
let current_token = currentResponse['token'];
old_unique_token = current_token;
await chai.request(app) // note 'await' here
.post('entities')
.set('Content-Type', 'application/json')
.set('vrc-access-token', current_token)
.send({ "key": "organizations", "operation": "findAll" })
.then(function (err, res) { // not 'then', not 'end'
currentResponse = res.body;
expect(err).to.be.null;
expect(res).to.have.status(api_status);
});
});
Бегущий по тестам автоматически await
выполнит вашу функцию.