javascript - How do async tests work in intern? -
how asynchronous tests work in intern testing framework? have tried them run in example, async test passes without waiting callback run.
it('should connect in 5 seconds', function () { var dfd = this.async(5000); conn.connect(credentials, dfd.callback(function(result) { expect(result).to.... })); }
the test passes immediately. doing wrong?
dfd.callback
doesn’t execute until executed. keep in mind designed promise callbacks (i.e. function passed promise.then
), not node.js-style callbacks argument might error (i.e. function (error, result) {}
). not check see if error passed argument.
without knowing conn
is, seeing how passing dfd.callback
argument not promise, suspicion trying use node.js-style callback , call erroring immediately. may provide convenience wrapper these types of callbacks in future convert them promise interface, until then, need this:
it('should connect in 5 seconds', function () { var dfd = this.async(5000); conn.connect(credentials, dfd.callback(function(error, result) { if (error) { throw error; } expect(result).to.... })); });
otherwise, without knowing conn
, seeing actual assertion is, it’s hard issue here. long nothing inside callback throws error, test considered successful.
edit: based on comments above sounds callback event listener called multiple times different information. in case, this:
it('should connect in 5 seconds', function () { var dfd = this.async(5000); conn.connect(credentials, dfd.rejectonerror(function (result) { if (result !== 'what want') { return; } expect(result).to.... // other tests… // nothing threw error, successful test dfd.resolve(); })); });
dfd.rejectonerror
works dfd.callback
except not automatically resolve promise; @ end.
Comments
Post a Comment