From 50ffa9d85ed55bf905e454b417171f080ebb4528 Mon Sep 17 00:00:00 2001 From: Hristo Iliev Date: Sun, 18 Dec 2016 08:56:14 +0200 Subject: [PATCH] Enable use of custom log function (#379) * Enable use of custom log function * Add test for custom log function --- debug.js | 2 +- test/debug_spec.js | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/debug.js b/debug.js index 7b0632db..4d3c7f27 100644 --- a/debug.js +++ b/debug.js @@ -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); } diff --git a/test/debug_spec.js b/test/debug_spec.js index b0339218..136937aa 100644 --- a/test/debug_spec.js +++ b/test/debug_spec.js @@ -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); + }); + }); + }); +});