-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.spec.ts
71 lines (59 loc) · 1.6 KB
/
logger.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
import {
expect as chaiExpect,
} from 'chai';
import {
createLogger,
} from './logger';
import { randomString } from '../utils';
describe('Logger', () => {
let logger: any, mock: any, mockLog: any, str: string;
beforeEach(() => {
str = randomString();
mock = jest.fn(() => {});
mockLog = (_: any) => {
return (_: any) => {
return (_: any) => {
return mock();
};
}
};
logger = createLogger({ middleware: [{ middleware: mockLog }]})
});
it('should instantiate', async () => {
chaiExpect(logger).to.be.not.null;
});
it('should log parameters', async () => {
logger.log(str);
expect(mock).toHaveBeenCalled();
});
it('should have runtime properties update', async () => {
const formatter = jest.fn((..._: any[]) => randomString());
const level = 'info';
const prefix = randomString();
const output = jest.fn((..._: any[]) => randomString());
mockLog = (api: any) => {
return (middleware: any) => {
return (params: any) => {
if (api.action.type === 'LOGGER_CREATE_LINE') {
const {
lineOptions,
} = params;
formatter(lineOptions.prefix, lineOptions.level);
output();
}
return middleware(params);
};
}
};
logger = createLogger({ middleware: [{ middleware: mockLog }]})
logger.updateOptions({
formatter,
level,
prefix,
output,
});
logger.log(str);
expect(formatter).toHaveBeenCalledWith(prefix, level);
expect(output).toHaveBeenCalled();
});
});