0

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? while debug when I put BP on the JSON.parse it doesn't stops line after...

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);
});

1 Answers1

0

You have to remove the done callback and just return the 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.

MarcoL
  • 9,829
  • 3
  • 37
  • 50
  • Thanks a lot missed that part... btw any idea regard this?http://stackoverflow.com/questions/38474419/run-html-file-after-code-coverage-finish-in-grunt –  Jul 20 '16 at 11:02