From 4bfd9fddc7cf99c86defb38ad7f5a6005132560f Mon Sep 17 00:00:00 2001 From: TechWIthTy <37724661+TechWithTy@users.noreply.github.com> Date: Sat, 11 Oct 2025 16:37:02 -0600 Subject: [PATCH] fix: install jest types for prod builds --- package.json | 8 ++++---- pnpm-lock.yaml | 8 ++++---- src/utils/testHelpers/auth.ts | 22 +++++++++++++++------- tsconfig.app.json | 2 +- tsconfig.json | 2 +- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 26ec2d6a..1f45311a 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,8 @@ "@tabler/icons-react": "^3.33.0", "@tailwindcss/typography": "^0.5.15", "@tanstack/react-query": "^5.72.1", - "@types/leaflet": "^1.9.20", + "@types/jest": "^29.5.14", + "@types/leaflet": "^1.9.20", "@upstash/ratelimit": "^2.0.6", "@upstash/redis": "^1.35.3", "analytics": "^0.8.19", @@ -157,9 +158,8 @@ "@eslint/js": "^9.9.0", "@svgr/webpack": "^8.1.0", "@testing-library/jest-dom": "^6.6.3", - "@testing-library/react": "^16.3.0", - "@types/dompurify": "^3.2.0", - "@types/jest": "^29.5.14", + "@testing-library/react": "^16.3.0", + "@types/dompurify": "^3.2.0", "@types/node": "^22.5.5", "@types/node-fetch": "^2.6.12", "@types/react": "^18.3.21", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4479dbe8..9e85cf21 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -143,6 +143,9 @@ importers: '@tanstack/react-query': specifier: ^5.72.1 version: 5.81.2(react@18.3.1) + '@types/jest': + specifier: ^29.5.14 + version: 29.5.14 '@types/leaflet': specifier: ^1.9.20 version: 1.9.20 @@ -321,9 +324,6 @@ importers: '@types/dompurify': specifier: ^3.2.0 version: 3.2.0 - '@types/jest': - specifier: ^29.5.14 - version: 29.5.14 '@types/node': specifier: ^22.5.5 version: 22.15.33 @@ -2323,7 +2323,7 @@ packages: resolution: {integrity: sha512-FkBMwD+qbGQeMu1cOHnuGB6x4yzPjho8ap5WtbEJ26umhgqVXbhekKUQO+hZEL1vU92a3wHwdp0HAcqAUF5iDg==} peerDependencies: '@types/react': '*' - react: 18.3.1 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true diff --git a/src/utils/testHelpers/auth.ts b/src/utils/testHelpers/auth.ts index 17e74912..ff651394 100644 --- a/src/utils/testHelpers/auth.ts +++ b/src/utils/testHelpers/auth.ts @@ -23,14 +23,22 @@ export function createSession(overrides: Partial = {}): Session { }; } +type FetchMock = typeof global.fetch & { + mockResolvedValueOnce: (value: Response) => unknown; + mockRejectedValueOnce: (error: unknown) => unknown; + mockReset: () => unknown; +}; + +const getFetchMock = () => global.fetch as FetchMock; + /** * Sets the global fetch mock to return a resolved response with the provided payload. */ export function mockFetchResponse({ - status = 200, - json, - text, - headers = {}, + status = 200, + json, + text, + headers = {}, }: MockFetchResponseOptions) { const bodyJson = json; const bodyText = text ?? (json ? JSON.stringify(json) : ""); @@ -56,14 +64,14 @@ export function mockFetchResponse({ redirected: false, }; - (global.fetch as jest.Mock).mockResolvedValueOnce(mockResponse as Response); + getFetchMock().mockResolvedValueOnce(mockResponse as Response); } /** * Sets the global fetch mock to reject with an error. */ export function mockFetchReject(error: Error) { - (global.fetch as jest.Mock).mockRejectedValueOnce(error); + getFetchMock().mockRejectedValueOnce(error); } /** @@ -77,5 +85,5 @@ export function createRequest(url: string, init?: RequestInit) { * Resets shared mocks between tests. */ export function resetMocks() { - (global.fetch as jest.Mock).mockReset(); + getFetchMock().mockReset(); } diff --git a/tsconfig.app.json b/tsconfig.app.json index 9c92feec..2b1f17cd 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -7,7 +7,7 @@ "lib": ["ES2020", "DOM", "DOM.Iterable"], "module": "ESNext", "skipLibCheck": true, - "types": ["@testing-library/jest-dom"], + "types": ["@testing-library/jest-dom", "jest"], "moduleResolution": "bundler", "allowImportingTsExtensions": true, diff --git a/tsconfig.json b/tsconfig.json index ac20be01..b6e39cc0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,7 @@ "paths": { "@/*": ["./src/*"] }, - "types": ["@testing-library/jest-dom"], + "types": ["@testing-library/jest-dom", "jest"], "noImplicitAny": false, "noUnusedParameters": false, "skipLibCheck": true,