UNPKG

th

Version:

th.en - make it painless to adapt between callbacks and promises

58 lines (41 loc) 1.09 kB
var chai = require('chai') chai.should() var Q = require('q') describe('then', function () { var then = require('../') it('goes to promises from callbacks', function (done) { function oldschool(cb) { cb(null, 'foo') } oldschool(then()) then(function (val) { val.should.equal('foo') }) .then(done, done) }) it('callbacks to promises error case', function (done) { function old(cb) { cb(new Error('woah!')) } old(then()) then(function (val) { done(new Error('should not be resolved')) }, function (err) { err.message.should.equal('woah!') }) .then(done, done) }) it('goes to callbacks from promises', function (done) { then.callback(Q(), done) }) it('promises to callbacks error case', function (done) { then.callback(Q.reject(new Error('it\'s not a big truck')), function (err, val) { err.message.should.equal('it\'s not a big truck') done() }) }) it('has an alias for silly npm', function () { var th = then th.en.should.equal(then) }) })