Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/debug.js
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
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 () {
});
});
});

});