all files / node-err-handler/ test.js

100% Statements 23/23
100% Branches 0/0
87.5% Functions 7/8
100% Lines 23/23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37    1×   1× 1× 1×   1× 1× 1× 1× 1× 1×     1× 1× 1× 1× 1× 1× 1×         1× 1× 1× 1× 1× 1×        
'use strict';
 
var sinon = require('sinon');
 
describe('err-handler', function(){
  var errHandler = require('./');
  var sinon = require('sinon');
 
  describe('when an error occurs', function() {
    it('should pass errors to handler', function(){
      var err = new Error();
      var handler = sinon.stub();
      errHandler(handler, function(){})(err);
      sinon.assert.calledWith(handler, err);
    });
 
    describe('when the handler does not return undefined', function() {
      it('should pass the error back to the callback', function() {
        var err = new Error();
        var handler = sinon.stub().returns(err);
        var callback = sinon.stub();
        errHandler(handler, callback)(err);
        sinon.assert.calledWith(callback, err);
      });
    });
  });
 
  describe('when no error occurs', function() {
    it('calls cb with arguments', function(){
      var handler = sinon.stub();
      var callback = sinon.stub();
      errHandler(handler, callback)(null, 5);
      sinon.assert.calledWith(callback, null, 5);
    });
  });
});