|
1 | | -import { ok } from "assert"; |
2 | 1 | import "ts-jest"; |
| 2 | +import { ok } from "assert"; |
3 | 3 | import { Logger } from "../../src/index.js"; |
4 | | -import { mockConsoleLog } from "./helper.js"; |
| 4 | +import { getConsoleLog, mockConsoleLog } from "./helper.js"; |
5 | 5 |
|
6 | 6 | class MissingSetter { |
7 | | - get test(): string { |
| 7 | + get testProp(): string { |
8 | 8 | return "test"; |
9 | 9 | } |
10 | 10 | } |
11 | 11 |
|
12 | 12 | const missingSetter = { |
13 | | - get test(): string { |
| 13 | + get testProp(): string { |
14 | 14 | return "test"; |
15 | | - } |
16 | | -} |
| 15 | + }, |
| 16 | +}; |
17 | 17 |
|
18 | 18 | describe("Getters and setters", () => { |
19 | 19 | beforeEach(() => { |
20 | 20 | mockConsoleLog(true, false); |
21 | 21 | }); |
22 | | - test("[class] should not print getters", (): void => { |
| 22 | + |
| 23 | + test("[class] should not print getters on class instance (prototype)", (): void => { |
| 24 | + // Node.js issue: https://github.com/nodejs/node/issues/30183 |
23 | 25 | const logger = new Logger({ |
24 | | - type: "hidden", |
| 26 | + type: "pretty", |
25 | 27 | }); |
26 | 28 | const missingSetterObj = new MissingSetter(); |
27 | | - |
28 | 29 | const result = logger.info(missingSetterObj); |
29 | | - |
30 | 30 | ok(result); |
31 | | - Object.keys(result).forEach((key) => { |
32 | | - expect(key).not.toBe("test"); |
33 | | - }); |
| 31 | + expect(Object.keys(result)).not.toContain("testProp"); |
| 32 | + expect(getConsoleLog()).not.toContain("testProp"); |
34 | 33 | }); |
| 34 | + |
35 | 35 | test("[object] should print getters", (): void => { |
36 | 36 | const logger = new Logger({ |
37 | | - type: "hidden", |
| 37 | + type: "pretty", |
38 | 38 | }); |
39 | 39 | const result = logger.info(missingSetter); |
40 | | - expect(result).toContain("test"); |
| 40 | + ok(result); |
| 41 | + expect(Object.keys(result)).toContain("testProp"); |
| 42 | + expect(getConsoleLog()).toContain("testProp"); |
41 | 43 | }); |
42 | 44 | }); |
0 commit comments