Helper functions for promises with Q on NodeJS. The functions are pure and curried with Ramda.
$ npm install alien-node-q-utils --save
Run the specs
$ npm test
A pre-rejected promise that throws the rejection into an expected catch block.
it('should pre-reject a promise',function(done){rejectedPromise('foo').catch(function(err){expect(err).toBe('foo');done();})});A pre-resolved promise that passes the resolution into the expected then block.
it('should pre-resolve a promise',function(done){resolvedPromise('foo').then(function(data){expect(data).toBe('foo');done();})});Given a function signature of fn(deferred, err, data) this will reject deferred if err is provided,
otherwise resolve deferred with data.
- Don't forget this function is curried, so the arity must be recognized. (If you omit the
dataparam, you will get a function that accepts only thedataparam.)
varmockPromiseNoError=function(resolveWith){vardeferred=Q.defer();rejectOnErrorOrResolve(deferred,undefined,resolveWith);returndeferred.promise;};varmockPromiseWithError=function(err){vardeferred=Q.defer();rejectOnErrorOrResolve(deferred,err,undefined);returndeferred.promise;};it('should resolve if no error is provided',function(done){vardeferred=Q.defer();mockPromiseNoError('foo').then(function(data){expect(data).toBe('foo');done();});});it('should reject if error is provided',function(done){vardeferred=Q.defer();mockPromiseWithError('foo').catch(function(err){expect(err).toBe('foo');done();});});- Need specs and descriptions for new mapP methods