Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 119
Supported all actual node versions (LTS + Current). Browsers support is about last three versions of evergreen browsers and IE9+ (IE9 and IE10 with known engine bugs - See Known Bugs page).
E.g. with mocha you should call done callback argument with or without error. With last version of mocha you can return promise and mocha will evaluate it.
it('should call something',functiontest(){library.asyncCall(function(err,result){should.fail();// this probably will not be called because test finished as soon `test` function finished// and assertion will look like not working})})it('should call something2',functiontest(done){library.asyncCall(function(err,result){should.fail();// in this case you will see test timeouts, again because done not called})})it('should call something3',functiontest(done){library.asyncCall(function(err,result){should.fail();done();// that is it, done called and mocha will wait for it call})})In the last example above, if the assertion fails, the test may still timeout.
The assertion library throws an error and done() never gets called.
Here is a fix:
it('should call something4',functiontest(done){library.asyncCall(function(err,result){if(err)returndone(err);try{should.fail();// the assertionreturndone();// if the assertion passes, the done will be called}catch(err2){// here we catch an error which assertion throws when it failsreturndone(err2);// we need to call done(err2) to finish the test which failed}})})With promises it is similar:
// in this case again assertion will not happen because test will finished before .then callback calledit('should call something',functiontest(){library.asyncCall.then(function(result){should.fail();})})// again you will see timeoutit('should call something2',functiontest(done){library.asyncCall.then(function(result){should.fail();})})// correct wayit('should call something3',functiontest(done){//return required for promise evaluationreturnlibrary.asyncCall(function(err,result){should.fail();}).then(function(){done()},done);//first argument is wrapped `done` in case you return something in previous call})// correct way with last mochait('should call something4',functiontest(){//just return it and mocha will do restreturnlibrary.asyncCall(function(err,result){should.fail();})})When you call require('should'), Object.prototype extended with should getter. So
varshould=require('should');deleteObject.prototype.should;//use should that was returnedIf you think that should is confusing word for invoking it as a functions, you always can use others like assert, expect, must etc.
varshould=require('should');varassert=should,expect=should;assert.exist(null);expect({a: 1}).to.have.property('a');Or
Object.defineProperty(Object.prototype,'must',{get: function(){returnthis.should;//or should(this);},enumerable: false});({a :1)).must.have.property('a');Object.defineProperty(global, 'should', {
value: should
});
or
global.should = require('should').noConflict();
should.extend();