Skip to content

Commit

Permalink
Fix bug that would occure if process.env.DEBUG is a non-string value. (
Browse files Browse the repository at this point in the history
…#444)

Connects to #443
  • Loading branch information
LucianBuzzo authored and thebigredgeek committed Apr 20, 2017
1 parent 2f3ebf4 commit 1f01b70
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
19 changes: 12 additions & 7 deletions test/debug_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -20,28 +20,32 @@ 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');

expect(log.log).to.have.been.calledOnce;
});
});

describe('custom functions', function () {
var log;

Expand All @@ -59,4 +63,5 @@ describe('debug', function () {
});
});
});

});

0 comments on commit 1f01b70

Please sign in to comment.