[英]Error while running async test
I use the following code as mocha test and I got error ""before all" hook failed" 我将以下代码用作摩卡测试,但出现错误““之前”挂钩失败“
I use the before event but not sure what I'm doing wrong here,any idea? 我使用before事件,但不确定在这里做错了什么吗? while debug when I put BP on the JSON.parse it doesn't stops line after...
当我将BP放在JSON.parse上时进行调试时,它不会在之后停止行...
describe("Validations", function () {
before(function (done) {
var valid = require('../utils/valid');
_provideConfig()
.then(function (config) {
isValidURL = valid.url(config, "test2")
done();
}).done();
});
it("Validate URL ", function () {
expect(isValidURL).to.be.true;
});
});
_provideConfig = function () {
return new Promise(function (resolve, reject) {
var configJSON = {
"providers": [
{
"replace": {
"path": "cmd1",
"inc": "upd"
},
"save": {
"path": "test2",
"inc": "upd2"
}
}
]
};
var config = JSON.parse(configJSON);
console.log(config);
resolve(config);
});
You have to remove the done
callback and just return the promise. 您必须删除
done
回调并仅返回promise。
before(function () {
var valid = require('../utils/valid');
return _provideConfig()
.then(function (config) {
isValidURL = valid.url(config, "test2");
});
});
When it says in the documentation that Mocha supports promises, it means that you have to return a promise so that Mocha can handle it. 当在文档中说Mocha支持诺言时,这意味着您必须返回诺言,以便Mocha可以处理它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.