Skip to content

Commit 31466c6

Browse files
committed
Add utils
1 parent 26b7636 commit 31466c6

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

jest.utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function makeMockResponse(responseData: string, url: string, init?: ResponseInit): Response {
2+
const response = new Response(responseData, init);
3+
Object.defineProperty(response, 'url', { value: url });
4+
return response;
5+
}

src/context/StacApiProvider.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import { render, screen, waitFor } from '@testing-library/react';
33
import { QueryClient, QueryClientProvider, useQueryClient } from '@tanstack/react-query';
44
import { StacApiProvider } from './index';
55
import { useStacApiContext } from './useStacApiContext';
6+
import { makeMockResponse } from '../../jest.utils';
67

78
// Mock fetch for testing - returns a successful response
89
beforeEach(() => {
910
(global.fetch as jest.Mock) = jest.fn((url: string) => {
10-
const response = new Response(JSON.stringify({ links: [] }));
11-
Object.defineProperty(response, 'url', { value: url });
12-
return Promise.resolve(response);
11+
return Promise.resolve(makeMockResponse(JSON.stringify({ links: [] }), url));
1312
});
1413
});
1514

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"strictNullChecks": true,
1717
"allowSyntheticDefaultImports": true
1818
},
19-
"include": ["src", "jest.setup.ts", "vite.config.ts"],
19+
"include": ["src", "jest.setup.ts", "vite.config.ts", "jest.utils.ts"],
2020
"exclude": ["node_modules", "dist"]
2121
}

0 commit comments

Comments
 (0)