mirror of
https://github.com/debug-js/debug.git
synced 2026-01-25 16:42:28 +00:00
Enable use of custom log function (#379)
* Enable use of custom log function * Add test for custom log function
This commit is contained in:
parent
1c625d4578
commit
50ffa9d85e
2
debug.js
2
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);
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user