/
debug_spec.js
93 lines (69 loc) · 1.94 KB
/
debug_spec.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* global describe, it, context, beforeEach */
'use strict';
var chai
, expect
, debug
, sinon
, sinonChai;
if (typeof module !== 'undefined') {
chai = require('chai');
expect = chai.expect;
debug = require('../src/index');
sinon = require('sinon');
sinonChai = require("sinon-chai");
chai.use(sinonChai);
}
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;
beforeEach(function () {
debug.enable('test');
log = debug('test');
});
context('with log function', function () {
it('uses it', function () {
log.log = sinon.spy();
log('using custom log function');
expect(log.log).to.have.been.calledOnce;
});
});
});
describe('extend namespace', function () {
var log;
beforeEach(function () {
debug.enable('foo');
log = debug('foo');
});
it('should extend namespace', function () {
var logBar = log.extend('bar');
expect(logBar.namespace).to.be.equal('foo:bar');
});
it('should extend namespace with custom delimiter', function () {
var logBar = log.extend('bar', '--');
expect(logBar.namespace).to.be.equal('foo--bar');
});
it('should extend namespace with empty delimiter', function () {
var logBar = log.extend('bar', '');
expect(logBar.namespace).to.be.equal('foobar');
});
});
});