Skip to content

Commit 15a21e0

Browse files
committed
fix(tests): resolve TypeScript compilation errors in commit.test.ts
- Import MockInstance from vitest for precise spy type declarations - Replace generic ReturnType<typeof vi.spyOn> with explicit MockInstance<[...], R> types - Fix process.exit mock cast to use correct Node.js signature (string | number | null) - Add 'as typeof spy' casts for stderr/stdout write overloads
1 parent bfb222a commit 15a21e0

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/commands/commit.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2+
import type { MockInstance } from 'vitest';
23

34
// ── Module mocks ──────────────────────────────────────────────────────────────
45

@@ -116,17 +117,17 @@ function setupHappyPath() {
116117
}
117118

118119
describe('runCommit', () => {
119-
let processExitSpy: ReturnType<typeof vi.spyOn>;
120-
let stderrSpy: ReturnType<typeof vi.spyOn>;
121-
let stdoutSpy: ReturnType<typeof vi.spyOn>;
120+
let processExitSpy: MockInstance<[code?: string | number | null | undefined], never>;
121+
let stderrSpy: MockInstance<[str: string | Uint8Array, encoding?: BufferEncoding, cb?: (err?: Error | null) => void], boolean>;
122+
let stdoutSpy: MockInstance<[str: string | Uint8Array, encoding?: BufferEncoding, cb?: (err?: Error | null) => void], boolean>;
122123

123124
beforeEach(() => {
124125
vi.clearAllMocks();
125-
processExitSpy = vi.spyOn(process, 'exit').mockImplementation((() => {
126+
processExitSpy = vi.spyOn(process, 'exit').mockImplementation((_code?: string | number | null) => {
126127
throw new Error('process.exit called');
127-
}) as (code?: number) => never);
128-
stderrSpy = vi.spyOn(process.stderr, 'write').mockImplementation(() => true);
129-
stdoutSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
128+
});
129+
stderrSpy = vi.spyOn(process.stderr, 'write').mockImplementation(() => true) as typeof stderrSpy;
130+
stdoutSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true) as typeof stdoutSpy;
130131
});
131132

132133
afterEach(() => {

0 commit comments

Comments
 (0)