-
Notifications
You must be signed in to change notification settings - Fork 13.5k
/
Copy pathlogging.spec.ts
113 lines (82 loc) · 3.33 KB
/
logging.spec.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
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
112
113
import { config } from '@global/config';
import { printIonError, printIonWarning } from '../index';
describe('Logging', () => {
describe('#printIonWarning', () => {
let consoleWarnSpy: jest.SpyInstance;
beforeEach(() => {
consoleWarnSpy = jest.spyOn(console, 'warn');
// Suppress console.warn output from polluting the test output
consoleWarnSpy.mockImplementation(() => {});
});
afterEach(() => {
consoleWarnSpy.mockRestore();
});
describe('when the logLevel configuration is not set', () => {
it('logs a warning to the console', () => {
config.set('logLevel', undefined);
printIonWarning('This is a warning message');
expect(consoleWarnSpy).toHaveBeenCalledWith('[Ionic Warn]: This is a warning message');
});
});
describe("when the logLevel configuration is set to 'WARN'", () => {
it('logs a warning to the console', () => {
config.set('logLevel', 'WARN');
printIonWarning('This is a warning message');
expect(consoleWarnSpy).toHaveBeenCalledWith('[Ionic Warn]: This is a warning message');
});
});
describe("when the logLevel configuration is set to 'ERROR'", () => {
it('does not log a warning to the console', () => {
config.set('logLevel', 'ERROR');
printIonWarning('This is a warning message');
expect(consoleWarnSpy).not.toHaveBeenCalled();
});
});
describe("when the logLevel configuration is set to 'OFF'", () => {
it('does not log a warning to the console', () => {
config.set('logLevel', 'OFF');
printIonWarning('This is a warning message');
expect(consoleWarnSpy).not.toHaveBeenCalled();
});
});
});
describe('#printIonError', () => {
let consoleErrorSpy: jest.SpyInstance;
beforeEach(() => {
consoleErrorSpy = jest.spyOn(console, 'error');
// Suppress console.error output from polluting the test output
consoleErrorSpy.mockImplementation(() => {});
});
afterEach(() => {
consoleErrorSpy.mockRestore();
});
describe('when the logLevel configuration is not set', () => {
it('logs an error to the console', () => {
config.set('logLevel', undefined);
printIonError('This is an error message');
expect(consoleErrorSpy).toHaveBeenCalledWith('[Ionic Error]: This is an error message');
});
});
describe("when the logLevel configuration is set to 'ERROR'", () => {
it('logs an error to the console', () => {
config.set('logLevel', 'ERROR');
printIonError('This is an error message');
expect(consoleErrorSpy).toHaveBeenCalledWith('[Ionic Error]: This is an error message');
});
});
describe("when the logLevel configuration is set to 'WARN'", () => {
it('logs an error to the console', () => {
config.set('logLevel', 'WARN');
printIonError('This is an error message');
expect(consoleErrorSpy).toHaveBeenCalledWith('[Ionic Error]: This is an error message');
});
});
describe("when the logLevel configuration is set to 'OFF'", () => {
it('does not log an error to the console', () => {
config.set('logLevel', 'OFF');
printIonError('This is an error message');
expect(consoleErrorSpy).not.toHaveBeenCalled();
});
});
});
});