Skip to content

Commit c70e4ed

Browse files
committed
fix(test): add jest setup for Next.js 15 compatibility
- Polyfill TextEncoder/TextDecoder (jsdom lacks these) - Mock next-runtime-env to avoid loading Next.js server stack (next/cache pulls Request/Response/ReadableStream not in jsdom) - Fixes CI test failures (ReferenceError: TextEncoder is not defined)
1 parent f96d230 commit c70e4ed

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const createJestConfig = nextJest({
1111
/** @type {import('jest').Config} */
1212
const customJestConfig = {
1313
// Add more setup options before each test is run
14-
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
14+
setupFiles: ['<rootDir>/jest.setup.js'],
1515
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
1616
moduleDirectories: ['node_modules', '<rootDir>/'],
1717
testEnvironment: 'jest-environment-jsdom',

jest.setup.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Polyfill TextEncoder/TextDecoder for Next.js 15 in Jest (jsdom lacks these)
2+
const { TextEncoder, TextDecoder } = require('util');
3+
global.TextEncoder = TextEncoder;
4+
global.TextDecoder = TextDecoder;
5+
6+
// Mock next-runtime-env to avoid loading Next.js server stack (next/cache, etc.)
7+
jest.mock('next-runtime-env', () => ({
8+
PublicEnvProvider: ({ children }) => children,
9+
useEnvContext: () => ({
10+
NEXT_PUBLIC_PREMIUM_TOKEN_SYMBOL: 'FUSD',
11+
NEXT_PUBLIC_PRODUCT_CONTRACT_ADDRESS: '0x0000000000000000000000000000000000000000',
12+
NEXT_PUBLIC_FLIGHT_NFT_CONTRACT_ADDRESS: '0x0000000000000000000000000000000000000000',
13+
NEXT_PUBLIC_AIRPORTS_WHITELIST: '',
14+
NEXT_PUBLIC_AIRPORTS_BLACKLIST: '',
15+
NEXT_PUBLIC_DEPARTURE_DATE_DATE_FROM: undefined,
16+
NEXT_PUBLIC_DEPARTURE_DATE_MIN_DAYS: '14',
17+
}),
18+
}));

0 commit comments

Comments
 (0)