1.0.3 • Published 2 years ago

alien-node-q-utils v1.0.3

Weekly downloads
131
License
MIT
Repository
github
Last release
2 years ago

alien-node-q-utils

Helper functions for promises with Q on NodeJS. The functions are pure and curried with Ramda.

Build Status Coverage Status npm version Dependency Status

Install

$ npm install alien-node-q-utils --save

Run the specs

$ npm test

Methods

rejectedPromise

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();
      })
  });

resolvedPromise

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();
      })
  });

rejectOnErrorOrResolve

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 data param, you will get a function that accepts only the data param.)
  var mockPromiseNoError = function(resolveWith) {
    var deferred = Q.defer();
    rejectOnErrorOrResolve(deferred, undefined, resolveWith);
    return deferred.promise;
  };
  
  var mockPromiseWithError = function(err) {
    var deferred = Q.defer();
    rejectOnErrorOrResolve(deferred, err, undefined);
    return deferred.promise;
  };

  it('should resolve if no error is provided', function(done) {
    var deferred = Q.defer();
    mockPromiseNoError('foo')
      .then(function(data) {
        expect(data).toBe('foo');
        done();
      });
  });
  
  it('should reject if error is provided', function(done) {
    var deferred = Q.defer();
    mockPromiseWithError('foo')
      .catch(function(err) {
        expect(err).toBe('foo');
        done();
      });
  });

TODO

  • Need specs and descriptions for new mapP methods
1.0.3

2 years ago

1.0.2

9 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago