简体   繁体   English

运行异步测试时出错

[英]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.

相关问题 开玩笑地运行异步测试时出现超时错误 - Getting TimeOut Error while running asynchronous test in jest 运行测试时出现“不是函数”错误(javascript、cypress) - Getting a "is not a function" error while running a test (javascript, cypress) 在运行Cucumber测试时,使用以下代码段引发错误和未定义的实现 - While running the Cucumber test throws error and undefined implement with the following snippet Apollo useQuery() 在 React 测试库中运行异步测试时抛出错误:ECONNREFUSED - Apollo useQuery() throws Error: ECONNREFUSED when running async test in React Testing Library 运行async.map时对数组进行排序 - sort array while async.map running 抛出错误:Describe 不是函数。 运行 Mocha 测试时出现此错误 - Throw Error: Describe is not a function. Getting this error while running Mocha Test 操纵up的异步功能,但会在测试中引发错误 - Puppeteer async function that works but raises error in test 异步测试不会失败失败 - Async test doesn't error on fail 使用Jasmine测试异步功能的错误处理 - Test error handling of async function with jasmine 运行{PORT = 4001 npm run test}此命令时节点JS错误 - Node JS error while running { PORT=4001 npm run test} this command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM