node.js - Unit test with promise not working -


im using mocha test api, problem function async , test suite called before getting resutls function, how can overcome this?

i try chain test following raise error empty test suite.

describe("validations", function () {      var validator = require('../utils/validator');     var isvalid = null;      validator.validatejs()         .then(function (args) {             isvalid = args;         }).then(function(){         it("init validations ", function () {             expect(isvalid).to.equal('valid1');         });     });  }) 

my initial usage following if call , expect inside before answer(isvalid) coming promise,any idea?

describe("validations", function () {      var validator = require('../utils/validator');     var isvalid = null;        validator.validatejs()         .then(function (args) {             isvalid = args;          }).done();      it("init validations ", function () {         expect(isvalid).to.equal('valid1');     });  }) 

use mocha's before().

describe("validations", function () {      var validator = require('../utils/validator');     var isvalid = null;      before(function(done) {         validator.validatejs()         .then(function (args) {             isvalid = args;             done();         })     })      it("init validations ", function () {         expect(isvalid).to.equal('valid1');     }); }) 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -