-
Notifications
You must be signed in to change notification settings - Fork 6
/
logger.test.ts
42 lines (36 loc) · 1.29 KB
/
logger.test.ts
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
import Logger from './../lib/logger';
describe("Logger", () => {
let consoleLog;
let consoleError;
beforeEach(() => {
consoleLog = jest.spyOn(console, 'log');
consoleError = jest.spyOn(console, 'error');
});
it('should not output messages to console if not enabled', () => {
Logger.enabled = false;
Logger.info('A simple message.');
expect(Logger.enabled).toBe(false);
expect(consoleLog).not.toBeCalled();
});
it('should output messages to console if "enabled" is true', () => {
Logger.enabled = true;
Logger.info('A simple message.');
expect(Logger.enabled).toBe(true);
expect(consoleLog).toBeCalledTimes(1);
expect(consoleLog).toBeCalledWith('A simple message.');
});
it('should output errors to console if "enabled" is false', () => {
Logger.enabled = false;
Logger.error('An error occured.');
expect(Logger.enabled).toBe(false);
expect(consoleError).toBeCalledTimes(1);
expect(consoleError).toBeCalledWith('An error occured.');
});
it('should output errors to console if "enabled" is true', () => {
Logger.enabled = true;
Logger.error('An error occured.');
expect(Logger.enabled).toBe(true);
expect(consoleError).toBeCalledTimes(1);
expect(consoleError).toBeCalledWith('An error occured.');
});
});