Skip to content

Commit 4dcf672

Browse files
committed
test: ensure if constructs are executing right to reach coverage of 100%
1 parent 1a9149c commit 4dcf672

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

spec/logger.spec.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,28 @@ describe('logger', () => {
7575
}
7676
)
7777

78-
it('should log a message at the specified level', () => {
79-
interface Test {
80-
logger: any
81-
}
82-
class Test {
83-
hello() {
84-
this.logger.debug('hello')
78+
it.each(['verbose', 'debug', 'info', 'warn', 'error'])(
79+
'should log a message at the specified level',
80+
(level) => {
81+
interface Test {
82+
logger: any
83+
}
84+
class Test {
85+
hello() {
86+
this.logger[level]('hello')
87+
}
8588
}
86-
}
8789

88-
loggerDecorator('test', { level: 'debug' })(Test)
89-
const testInstance = new Test()
90-
const consoleSpy = vi.spyOn(console, 'debug')
91-
testInstance.hello()
92-
expect(consoleSpy).toHaveBeenCalledOnce()
93-
})
90+
loggerDecorator('test', { level: level as any })(Test)
91+
const testInstance = new Test()
92+
93+
let consoleSpy
94+
if (level === 'verbose') consoleSpy = vi.spyOn(console, 'log')
95+
else consoleSpy = vi.spyOn(console, level as any)
96+
testInstance.hello()
97+
expect(consoleSpy).toHaveBeenCalledOnce()
98+
}
99+
)
94100

95101
it('should not log a message at a lower level', () => {
96102
interface Test {

0 commit comments

Comments
 (0)