Skip to content

Commit cb0c443

Browse files
committed
fix(cli): add double cast to mock fetch in tests to resolve preconnect
type error Fix TypeScript errors in test files where mock fetch objects were missing the 'preconnect' property. Use 'as unknown as typeof fetch' double cast pattern to properly type mock fetch implementations. Affected files: - cli/src/__tests__/integration/usage-refresh-on-completion.test.ts - cli/src/hooks/__tests__/use-usage-query.test.ts
1 parent 9422154 commit cb0c443

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

cli/src/__tests__/integration/usage-refresh-on-completion.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('Usage Refresh on SDK Completion', () => {
5252
}),
5353
{ status: 200, headers: { 'Content-Type': 'application/json' } },
5454
),
55-
)
55+
) as unknown as typeof fetch
5656
})
5757

5858
afterEach(() => {

cli/src/hooks/__tests__/use-usage-query.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ describe('fetchUsageData', () => {
4848
status: 200,
4949
headers: { 'Content-Type': 'application/json' },
5050
}),
51-
)
51+
) as unknown as typeof fetch
5252

5353
const result = await fetchUsageData({ authToken: 'test-token' })
5454

5555
expect(result).toEqual(mockResponse)
5656
})
5757

5858
test('should throw error on failed request', async () => {
59-
globalThis.fetch = mock(async () => new Response('Error', { status: 500 }))
59+
globalThis.fetch = mock(async () => new Response('Error', { status: 500 })) as unknown as typeof fetch
6060

6161
await expect(fetchUsageData({ authToken: 'test-token' })).rejects.toThrow(
6262
'Failed to fetch usage: 500',
@@ -120,7 +120,7 @@ describe('useUsageQuery', () => {
120120
status: 200,
121121
headers: { 'Content-Type': 'application/json' },
122122
}),
123-
)
123+
) as unknown as typeof fetch
124124

125125
const { result } = renderHook(() => useUsageQuery(), {
126126
wrapper: createWrapper(),
@@ -135,7 +135,7 @@ describe('useUsageQuery', () => {
135135
getAuthTokenSpy = spyOn(authModule, 'getAuthToken').mockReturnValue(
136136
'test-token',
137137
)
138-
const fetchMock = mock(async () => new Response('{}'))
138+
const fetchMock = mock(async () => new Response('{}')) as unknown as typeof fetch
139139
globalThis.fetch = fetchMock
140140

141141
const { result } = renderHook(() => useUsageQuery({ enabled: false }), {
@@ -152,7 +152,7 @@ describe('useUsageQuery', () => {
152152
getAuthTokenSpy = spyOn(authModule, 'getAuthToken').mockReturnValue(
153153
undefined,
154154
)
155-
const fetchMock = mock(async () => new Response('{}'))
155+
const fetchMock = mock(async () => new Response('{}')) as unknown as typeof fetch
156156
globalThis.fetch = fetchMock
157157

158158
renderHook(() => useUsageQuery(), {

0 commit comments

Comments
 (0)