]>
Commit | Line | Data |
---|---|---|
8727f598 | 1 | /* eslint-disable no-console */ |
d21cd6c1 SR |
2 | var expect = chai.expect; |
3 | ||
dfae3209 | 4 | import * as Log from '../core/util/logging.js'; |
dfae3209 | 5 | |
0aaf59c2 | 6 | import sinon from '../vendor/sinon.js'; |
dfae3209 | 7 | |
d21cd6c1 SR |
8 | describe('Utils', function() { |
9 | "use strict"; | |
10 | ||
d21cd6c1 SR |
11 | describe('logging functions', function () { |
12 | beforeEach(function () { | |
13 | sinon.spy(console, 'log'); | |
0ae5b50a | 14 | sinon.spy(console, 'debug'); |
d21cd6c1 SR |
15 | sinon.spy(console, 'warn'); |
16 | sinon.spy(console, 'error'); | |
e4fef7be | 17 | sinon.spy(console, 'info'); |
d21cd6c1 SR |
18 | }); |
19 | ||
20 | afterEach(function () { | |
0242c032 SM |
21 | console.log.restore(); |
22 | console.debug.restore(); | |
23 | console.warn.restore(); | |
24 | console.error.restore(); | |
25 | console.info.restore(); | |
26 | Log.init_logging(); | |
d21cd6c1 SR |
27 | }); |
28 | ||
29 | it('should use noop for levels lower than the min level', function () { | |
dfae3209 SR |
30 | Log.init_logging('warn'); |
31 | Log.Debug('hi'); | |
32 | Log.Info('hello'); | |
d21cd6c1 SR |
33 | expect(console.log).to.not.have.been.called; |
34 | }); | |
35 | ||
0ae5b50a | 36 | it('should use console.debug for Debug', function () { |
dfae3209 SR |
37 | Log.init_logging('debug'); |
38 | Log.Debug('dbg'); | |
0ae5b50a | 39 | expect(console.debug).to.have.been.calledWith('dbg'); |
e4fef7be | 40 | }); |
c464f47e | 41 | |
e4fef7be | 42 | it('should use console.info for Info', function () { |
dfae3209 SR |
43 | Log.init_logging('debug'); |
44 | Log.Info('inf'); | |
e4fef7be | 45 | expect(console.info).to.have.been.calledWith('inf'); |
d21cd6c1 SR |
46 | }); |
47 | ||
48 | it('should use console.warn for Warn', function () { | |
dfae3209 SR |
49 | Log.init_logging('warn'); |
50 | Log.Warn('wrn'); | |
d21cd6c1 SR |
51 | expect(console.warn).to.have.been.called; |
52 | expect(console.warn).to.have.been.calledWith('wrn'); | |
53 | }); | |
54 | ||
55 | it('should use console.error for Error', function () { | |
dfae3209 SR |
56 | Log.init_logging('error'); |
57 | Log.Error('err'); | |
d21cd6c1 SR |
58 | expect(console.error).to.have.been.called; |
59 | expect(console.error).to.have.been.calledWith('err'); | |
60 | }); | |
61 | }); | |
62 | ||
63 | // TODO(directxman12): test the conf_default and conf_defaults methods | |
64 | // TODO(directxman12): test decodeUTF8 | |
65 | // TODO(directxman12): test the event methods (addEvent, removeEvent, stopEvent) | |
66 | // TODO(directxman12): figure out a good way to test getPosition and getEventPosition | |
ee7d4c61 | 67 | // TODO(directxman12): figure out how to test the browser detection functions properly |
d21cd6c1 SR |
68 | // (we can't really test them against the browsers, except for Gecko |
69 | // via PhantomJS, the default test driver) | |
d21cd6c1 | 70 | }); |
8727f598 | 71 | /* eslint-enable no-console */ |