Skip to content

Commit a44c7d9

Browse files
author
georgiy.rusanov
committed
use real ws in expo
1 parent 2ed9453 commit a44c7d9

File tree

3 files changed

+61
-12
lines changed

3 files changed

+61
-12
lines changed

examples/expo-app/jest.setup.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Jest setup file for Expo app
2+
// This file configures the test environment to use real WebSocket instead of mocks
3+
4+
// Mock expo-router
5+
jest.mock('expo-router', () => ({
6+
useRouter: () => ({
7+
push: jest.fn(),
8+
replace: jest.fn(),
9+
back: jest.fn(),
10+
}),
11+
useLocalSearchParams: () => ({}),
12+
useGlobalSearchParams: () => ({}),
13+
}))
14+
15+
// Mock expo-constants
16+
jest.mock('expo-constants', () => ({
17+
expoConfig: {
18+
extra: {
19+
supabaseUrl: process.env.SUPABASE_URL || 'http://127.0.0.1:54321',
20+
supabaseAnonKey:
21+
process.env.SUPABASE_ANON_KEY ||
22+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0',
23+
},
24+
},
25+
}))
26+
27+
// Configure React Native to use real WebSocket
28+
const ReactNative = require('react-native')
29+
if (ReactNative.WebSocket && ReactNative.WebSocket.name === 'WSWebSocketDummy') {
30+
// Replace the dummy WebSocket with real one
31+
ReactNative.WebSocket = require('ws')
32+
}
33+
34+
// Global test setup
35+
global.console = {
36+
...console,
37+
// Uncomment to ignore a specific log level
38+
// log: jest.fn(),
39+
// debug: jest.fn(),
40+
// info: jest.fn(),
41+
// warn: jest.fn(),
42+
// error: jest.fn(),
43+
}

examples/expo-app/package-lock.json

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/expo-app/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,22 @@
4242
},
4343
"devDependencies": {
4444
"@babel/core": "^7.25.2",
45+
"@testing-library/react-native": "^13.2.0",
4546
"@types/jest": "^29.5.14",
4647
"@types/react": "~19.1.0",
4748
"eslint": "^9.25.0",
4849
"eslint-config-expo": "~9.2.0",
4950
"jest": "~29.7.0",
5051
"jest-expo": "~53.0.5",
5152
"typescript": "~5.8.3",
52-
"@testing-library/react-native": "^13.2.0"
53+
"ws": "^8.18.2"
5354
},
5455
"private": true,
5556
"jest": {
56-
"preset": "jest-expo"
57+
"preset": "jest-expo",
58+
"setupFilesAfterEnv": [
59+
"<rootDir>/jest.setup.js"
60+
],
61+
"testEnvironment": "node"
5762
}
5863
}

0 commit comments

Comments
 (0)