-
Notifications
You must be signed in to change notification settings - Fork 945
/
test.node.js
40 lines (36 loc) · 1.11 KB
/
test.node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* eslint-env mocha */
const assert = require('assert');
const util = require('util');
const sinon = require('sinon');
const debug = require('./src/node');
const formatWithOptionsSpy = sinon.spy(util, 'formatWithOptions');
beforeEach(() => {
formatWithOptionsSpy.resetHistory();
});
describe('debug node', () => {
describe('formatting options', () => {
it('calls util.formatWithOptions', () => {
debug.enable('*');
const stdErrWriteStub = sinon.stub(process.stderr, 'write');
const log = debug('formatting options');
log('hello world');
assert(util.formatWithOptions.callCount === 1);
stdErrWriteStub.restore();
});
it('calls util.formatWithOptions with inspectOpts', () => {
debug.enable('*');
const options = {
hideDate: true,
colors: true,
depth: 10,
showHidden: true
};
Object.assign(debug.inspectOpts, options);
const stdErrWriteStub = sinon.stub(process.stderr, 'write');
const log = debug('format with inspectOpts');
log('hello world2');
assert.deepStrictEqual(util.formatWithOptions.getCall(0).args[0], options);
stdErrWriteStub.restore();
});
});
});