-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathanylogger.spec.js
More file actions
111 lines (95 loc) · 3.08 KB
/
anylogger.spec.js
File metadata and controls
111 lines (95 loc) · 3.08 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { expect } from 'chai'
import anylogger from 'anylogger'
describe('anylogger([name, [options]]) => log', function() {
afterEach(function(){
// clear any loggers that were created
Object.keys(anylogger()).forEach(function(key){
delete anylogger()[key]
})
})
it('is a function', function(){
expect(anylogger).to.be.a('function')
})
it('returns a named logger when called with a name', function(){
var name = 'test'
var result = anylogger(name)
expect(result).to.be.a('function')
expect(result.name).to.equal(name)
})
it('returns the same logger when called multiple times with the same name', function(){
var name = 'test'
var expected = anylogger(name)
var actual = anylogger(name)
expect(actual).to.equal(expected)
})
it('accepts an optional options argument', function(){
var name = 'test'
var options = { level: 'info' }
var result = anylogger(name, options)
expect(result).to.be.a('function')
})
describe('log', function(){
it('is a function', function(){
var name = 'test'
var log = anylogger(name)
expect(log).to.be.a('function')
})
it('has a name that matches the name given to anylogger', function(){
var name = 'test'
var log = anylogger(name)
expect(log.name).to.equal(name)
})
it('has a method `trace`', function(){
var log = anylogger('test')
expect(log).to.have.property('trace')
expect(log.trace).to.be.a('function')
})
it('has a method `debug`', function(){
var log = anylogger('test')
expect(log).to.have.property('debug')
expect(log.debug).to.be.a('function')
})
it('has a method `log`', function(){
var log = anylogger('test')
expect(log).to.have.property('log')
expect(log.log).to.be.a('function')
})
it('has a method `info`', function(){
var log = anylogger('test')
expect(log).to.have.property('info')
expect(log.info).to.be.a('function')
})
it('has a method `warn`', function(){
var log = anylogger('test')
expect(log).to.have.property('warn')
expect(log.warn).to.be.a('function')
})
it('has a method `error`', function(){
var log = anylogger('test')
expect(log).to.have.property('error')
expect(log.error).to.be.a('function')
})
it('has a method `enabledFor`', function(){
var log = anylogger('test')
expect(log).to.have.property('enabledFor')
expect(log.enabledFor).to.be.a('function')
var log = anylogger('test')
expect(log.enabledFor('info')).to.equal(undefined)
})
it('can be invoked to log a message', function(){
var log = anylogger('test')
expect(() => log('message')).not.to.throw()
})
it('can be invoked with a level name as first argument to log a message at that level', function(){
var log = anylogger('test')
const old = log.info
let called = false
log.info = (...args) => {
called = true
old(...args)
}
log('info', 'message')
expect(called).to.equal(true)
})
})
})