Skip to content

Commit 41ef3be

Browse files
committed
fix(test): add optional chaining to mock restore calls in stdio tests
Fixed TypeError when calling mockRestore() on potentially undefined spies in afterEach hooks. Added optional chaining (?.) to safely restore mocks.
1 parent b572e3b commit 41ef3be

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

test/stdio/stderr.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ describe('stdio/stderr', () => {
4040

4141
afterEach(() => {
4242
// Restore spies
43-
writeSpy.mockRestore()
44-
cursorToSpy.mockRestore()
45-
clearLineSpy.mockRestore()
43+
writeSpy?.mockRestore()
44+
cursorToSpy?.mockRestore()
45+
clearLineSpy?.mockRestore()
4646

4747
// Restore original properties
4848
Object.defineProperty(stderr, 'isTTY', {

test/stdio/stdout.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ describe('stdio/stdout', () => {
4747

4848
afterEach(() => {
4949
// Restore spies
50-
writeSpy.mockRestore()
51-
cursorToSpy.mockRestore()
52-
clearLineSpy.mockRestore()
53-
clearScreenDownSpy.mockRestore()
50+
writeSpy?.mockRestore()
51+
cursorToSpy?.mockRestore()
52+
clearLineSpy?.mockRestore()
53+
clearScreenDownSpy?.mockRestore()
5454

5555
// Restore original properties
5656
Object.defineProperty(stdout, 'isTTY', {

0 commit comments

Comments
 (0)