node.js - How to check assertion error in Mocha when testing async code -


when testing async code mocha , 1 of asserts fails, mocha report timeout error. there way improve this? how know asserts failed , why?

mocha    contact     #getcontacts()       1) should return @ least 1 contact     0 passing (3s)   1 failing    1) contact #getcontacts() should return @ least 1 contact:      error: timeout of 3000ms exceeded. ensure done() callback being called in test. 

code:

var assert         = require("assert"); var contact        = require("../lib/contact.js"); var chai           = require('chai'); var should         = chai.should();  describe('contact', function() {   describe('#getcontacts()', function() {     it('should return @ least 1 contact', function(done) {       contact.getcontacts().then(function(contacts) {         assert.equal(4,2)          done()       });     })   }) }); 

the issue assertion fails, throws exception. causes promise rejected, there isn't notice. code checks if promise succeeds. if return promise, mocha check , fail test if promise rejected.

so want

it('should return @ least 1 contact', function() {     return contact.getcontacts().then(function(contacts) {       assert.equal(4,2);     }); });  

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -