Fix bug that would occure if process.env.DEBUG is a non-string value. (#444)

Connects to #443
This commit is contained in:
Lucian Buzzo 2017-04-20 19:04:28 +01:00 committed by Andrew E. Rhyne
parent 2f3ebf49c1
commit 1f01b70f88
2 changed files with 13 additions and 8 deletions

View File

@ -141,7 +141,7 @@ function enable(namespaces) {
exports.names = [];
exports.skips = [];
var split = (namespaces || '').split(/[\s,]+/);
var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
var len = split.length;
for (var i = 0; i < len; i++) {

View File

@ -6,11 +6,11 @@ var chai
, debug
, sinon
, sinonChai;
if (typeof module !== 'undefined') {
chai = require('chai');
expect = chai.expect;
debug = require('../src/index');
sinon = require('sinon');
sinonChai = require("sinon-chai");
@ -20,20 +20,24 @@ if (typeof module !== 'undefined') {
describe('debug', function () {
var log = debug('test');
log.log = sinon.stub();
it('passes a basic sanity check', function () {
expect(log('hello world')).to.not.throw;
});
it('allows namespaces to be a non-string value', function () {
expect(debug.enable(true)).to.not.throw;
});
context('with log function', function () {
beforeEach(function () {
debug.enable('test');
log = debug('test');
});
it('uses it', function () {
log.log = sinon.stub();
log('using custom log function');
@ -41,7 +45,7 @@ describe('debug', function () {
expect(log.log).to.have.been.calledOnce;
});
});
describe('custom functions', function () {
var log;
@ -59,4 +63,5 @@ describe('debug', function () {
});
});
});
});