Enable use of custom log function (#379)

* Enable use of custom log function

* Add test for custom log function
This commit is contained in:
Hristo Iliev 2016-12-18 08:56:14 +02:00 committed by Andrew E. Rhyne
parent 1c625d4578
commit 50ffa9d85e
2 changed files with 21 additions and 2 deletions

View File

@ -110,7 +110,7 @@ function createDebug(namespace) {
// apply env-specific formatting (colors, etc.)
exports.formatArgs.call(self, args);
var logFn = enabled.log || exports.log || console.log.bind(console);
var logFn = debug.log || exports.log || console.log.bind(console);
logFn.apply(self, args);
}

View File

@ -1,4 +1,5 @@
import { expect } from 'chai';
import { assert, spy } from 'sinon';
import debug from '../index';
@ -9,4 +10,22 @@ describe('debug', () => {
log('hello world');
});
});
})
describe('custom functions', () => {
let log;
beforeEach(() => {
debug.enable('test');
log = debug('test');
});
context('with log function', () => {
it('uses it', () => {
log.log = spy();
log('using custom log function');
assert.calledOnce(log.log);
});
});
});
});