Skip to content

Commit cfeb015

Browse files
committed
test: add test coverage for second parameter object
1 parent d44e3da commit cfeb015

File tree

1 file changed

+31
-36
lines changed

1 file changed

+31
-36
lines changed

test/index.spec.ts

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,83 +20,78 @@ describe('Logger', () => {
2020
consoleDebugSpy.mockRestore();
2121
});
2222

23-
it("should log a message when NODE_ENV is not 'production'", () => {
23+
it("should log a message with an optional parameter when NODE_ENV is not 'production'", () => {
2424
process.env.NODE_ENV = 'development';
2525
const message = 'Test log message';
26+
const additionalParam = { key: 'value' };
2627

27-
logger.log(message);
28+
logger.log(message, additionalParam);
2829

2930
expect(consoleLogSpy).toHaveBeenCalledWith(
30-
expect.stringMatching(/\[LOG\] .*: Test log message/)
31+
expect.stringMatching(/\[LOG\] .*: Test log message \{"key":"value"\}/)
3132
);
3233
});
3334

34-
it("should not log a message when NODE_ENV is 'production'", () => {
35-
process.env.NODE_ENV = 'production';
35+
it("should log a message without an optional parameter when NODE_ENV is not 'production'", () => {
36+
process.env.NODE_ENV = 'development';
3637
const message = 'Test log message';
3738

3839
logger.log(message);
3940

40-
expect(consoleLogSpy).not.toHaveBeenCalled();
41+
expect(consoleLogSpy).toHaveBeenCalledWith(
42+
expect.stringMatching(/\[LOG\] .*: Test log message/)
43+
);
4144
});
4245

43-
it("should warn a message when NODE_ENV is not 'production'", () => {
46+
it("should warn a message with an optional parameter when NODE_ENV is not 'production'", () => {
4447
process.env.NODE_ENV = 'development';
4548
const message = 'Test warn message';
49+
const additionalParam = [1, 2, 3];
4650

47-
logger.warn(message);
51+
logger.warn(message, additionalParam);
4852

4953
expect(consoleWarnSpy).toHaveBeenCalledWith(
50-
expect.stringMatching(/\[WARN\] .*: Test warn message/)
54+
expect.stringMatching(/\[WARN\] .*: Test warn message \[1,2,3\]/)
5155
);
5256
});
5357

54-
it("should not warn a message when NODE_ENV is 'production'", () => {
55-
process.env.NODE_ENV = 'production';
56-
const message = 'Test warn message';
57-
58-
logger.warn(message);
59-
60-
expect(consoleWarnSpy).not.toHaveBeenCalled();
61-
});
62-
63-
it("should error a message when NODE_ENV is not 'production'", () => {
58+
it("should error a message with an optional parameter when NODE_ENV is not 'production'", () => {
6459
process.env.NODE_ENV = 'development';
6560
const message = 'Test error message';
61+
const additionalParam = 'extra details';
6662

67-
logger.error(message);
63+
logger.error(message, additionalParam);
6864

6965
expect(consoleErrorSpy).toHaveBeenCalledWith(
70-
expect.stringMatching(/\[ERROR\] .*: Test error message/)
66+
expect.stringMatching(/\[ERROR\] .*: Test error message extra details/)
7167
);
7268
});
7369

74-
it("should not error a message when NODE_ENV is 'production'", () => {
75-
process.env.NODE_ENV = 'production';
76-
const message = 'Test error message';
77-
78-
logger.error(message);
79-
80-
expect(consoleErrorSpy).not.toHaveBeenCalled();
81-
});
82-
83-
it("should debug a message when NODE_ENV is not 'production'", () => {
70+
it("should debug a message with an optional parameter when NODE_ENV is not 'production'", () => {
8471
process.env.NODE_ENV = 'development';
8572
const message = 'Test debug message';
73+
const additionalParam = { debug: true };
8674

87-
logger.debug(message);
75+
logger.debug(message, additionalParam);
8876

8977
expect(consoleDebugSpy).toHaveBeenCalledWith(
90-
expect.stringMatching(/\[DEBUG\] .*: Test debug message/)
78+
expect.stringMatching(/\[DEBUG\] .*: Test debug message \{"debug":true\}/)
9179
);
9280
});
9381

94-
it("should not debug a message when NODE_ENV is 'production'", () => {
82+
it("should not log, warn, error, or debug a message when NODE_ENV is 'production'", () => {
9583
process.env.NODE_ENV = 'production';
96-
const message = 'Test debug message';
84+
const message = 'Test message';
85+
const additionalParam = { ignored: true };
9786

98-
logger.debug(message);
87+
logger.log(message, additionalParam);
88+
logger.warn(message, additionalParam);
89+
logger.error(message, additionalParam);
90+
logger.debug(message, additionalParam);
9991

92+
expect(consoleLogSpy).not.toHaveBeenCalled();
93+
expect(consoleWarnSpy).not.toHaveBeenCalled();
94+
expect(consoleErrorSpy).not.toHaveBeenCalled();
10095
expect(consoleDebugSpy).not.toHaveBeenCalled();
10196
});
10297
});

0 commit comments

Comments
 (0)