tak*_*aks 4 mocha.js node.js node-modules chai
当我运行我的函数时,它给了我错误:Resolution method is overspecified. Specify a callback *or* return a Promise; not both.任何人都可以检查我的代码,并帮助解决这个问题吗?我在这里放置了完整的代码
it('Get Organizations', async function (done) {
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;
chai.request(app)
.post('entities')
.set('Content-Type', 'application/json')
.set('vrc-access-token', current_token)
.send({ "key": "organizations", "operation": "findAll" })
.end(function (err, res) {
currentResponse = res.body;
expect(err).to.be.null;
expect(res).to.have.status(api_status);
done();
});
});
Run Code Online (Sandbox Code Playgroud)
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);
});
});
Run Code Online (Sandbox Code Playgroud)
测试运行器将await自动执行您的函数。
| 归档时间: |
|
| 查看次数: |
2418 次 |
| 最近记录: |