Skip to content

Commit fc9e951

Browse files
committed
refactor: refactor testing setup
1 parent 7355a9b commit fc9e951

4 files changed

Lines changed: 96 additions & 620 deletions

File tree

jest-setup.ts

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,99 @@
11
/* eslint-disable ts/ban-ts-comment */
22
/* eslint-disable no-restricted-globals */
3-
import '@testing-library/react-native/extend-expect';
3+
4+
// Mock react-native-worklets first
5+
jest.mock('react-native-worklets', () => ({
6+
__esModule: true,
7+
default: {},
8+
}));
9+
10+
// Mock react-native-reanimated
11+
jest.mock('react-native-reanimated', () => {
12+
const View = require('react-native').View;
13+
14+
return {
15+
__esModule: true,
16+
default: {
17+
View,
18+
ScrollView: View,
19+
createAnimatedComponent: (component: any) => component,
20+
},
21+
useSharedValue: jest.fn(() => ({ value: 0 })),
22+
useAnimatedStyle: jest.fn(fn => fn()),
23+
withTiming: jest.fn(value => value),
24+
withSpring: jest.fn(value => value),
25+
withDecay: jest.fn(value => value),
26+
withDelay: jest.fn((_, value) => value),
27+
withRepeat: jest.fn(value => value),
28+
withSequence: jest.fn((...values) => values[0]),
29+
cancelAnimation: jest.fn(),
30+
Easing: {
31+
linear: jest.fn(),
32+
ease: jest.fn(),
33+
quad: jest.fn(),
34+
cubic: jest.fn(),
35+
bezier: jest.fn(),
36+
in: jest.fn(fn => fn),
37+
out: jest.fn(fn => fn),
38+
inOut: jest.fn(fn => fn),
39+
},
40+
FadeIn: { duration: jest.fn(() => ({})) },
41+
FadeOut: { duration: jest.fn(() => ({})) },
42+
FadeInDown: { duration: jest.fn(() => ({})) },
43+
FadeInUp: { duration: jest.fn(() => ({})) },
44+
FadeInLeft: { duration: jest.fn(() => ({})) },
45+
FadeInRight: { duration: jest.fn(() => ({})) },
46+
SlideInDown: { duration: jest.fn(() => ({})) },
47+
SlideInUp: { duration: jest.fn(() => ({})) },
48+
SlideInLeft: { duration: jest.fn(() => ({})) },
49+
SlideInRight: { duration: jest.fn(() => ({})) },
50+
Layout: {},
51+
Keyframe: jest.fn(),
52+
};
53+
});
54+
55+
// Mock expo-localization
56+
jest.mock('expo-localization', () => ({
57+
getLocales: jest.fn(() => [
58+
{
59+
languageTag: 'en-US',
60+
languageCode: 'en',
61+
textDirection: 'ltr',
62+
digitGroupingSeparator: ',',
63+
decimalSeparator: '.',
64+
measurementSystem: 'metric',
65+
currencyCode: 'USD',
66+
currencySymbol: '$',
67+
regionCode: 'US',
68+
},
69+
]),
70+
}));
71+
72+
// Mock react-native-mmkv
73+
jest.mock('react-native-mmkv', () => ({
74+
MMKV: jest.fn(() => ({
75+
set: jest.fn(),
76+
getString: jest.fn(),
77+
getNumber: jest.fn(),
78+
getBoolean: jest.fn(),
79+
delete: jest.fn(),
80+
clearAll: jest.fn(),
81+
getAllKeys: jest.fn(() => []),
82+
})),
83+
useMMKVString: jest.fn((_key: string) => [undefined, jest.fn()]),
84+
useMMKVNumber: jest.fn((_key: string) => [undefined, jest.fn()]),
85+
useMMKVBoolean: jest.fn((_key: string) => [undefined, jest.fn()]),
86+
useMMKVObject: jest.fn((_key: string) => [undefined, jest.fn()]),
87+
createMMKV: jest.fn(() => ({
88+
set: jest.fn(),
89+
getString: jest.fn(),
90+
getNumber: jest.fn(),
91+
getBoolean: jest.fn(),
92+
delete: jest.fn(),
93+
clearAll: jest.fn(),
94+
getAllKeys: jest.fn(() => []),
95+
})),
96+
}));
497

598
// react-hook form setup for testing
699
// @ts-expect-error

jest.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ module.exports = {
77
'!**/coverage/**',
88
'!**/node_modules/**',
99
'!**/babel.config.js',
10-
'!**/jest.setup.js',
10+
'!**/jest-setup.ts',
1111
'!**/docs/**',
1212
'!**/cli/**',
1313
],
1414
moduleFileExtensions: ['js', 'ts', 'tsx'],
1515
transformIgnorePatterns: [
16-
`node_modules/(?!(?:.pnpm/)?((jest-)?react-native|@react-native(-community)?|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|@sentry/.*|native-base|react-native-svg))`,
16+
`node_modules/(?!(?:.pnpm/)?((jest-)?react-native|@react-native(-community)?|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|@sentry/.*|native-base|react-native-svg|@gorhom/.*|@shopify/.*|@tanstack/.*|react-native-reanimated|react-native-mmkv|react-native-nitro-modules|react-native-worklets|moti|zustand|tailwind-merge|tailwind-variants|uniwind))`,
1717
],
1818
coverageReporters: ['json-summary', ['text', { file: 'coverage.txt' }]],
1919
reporters: [

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
"@eslint-react/eslint-plugin": "^2.7.2",
106106
"@expo/config": "~12.0.13",
107107
"@tailwindcss/cli": "^4.0.0",
108-
"@testing-library/jest-dom": "^6.9.1",
109108
"@testing-library/react-native": "^13.3.3",
110109
"@types/i18n-js": "^4.0.1",
111110
"@types/invariant": "^2.2.37",
@@ -127,13 +126,11 @@
127126
"eslint-plugin-unicorn": "^62.0.0",
128127
"husky": "^9.1.7",
129128
"jest": "^29.7.0",
130-
"jest-environment-jsdom": "^30.2.0",
131129
"jest-expo": "~54.0.16",
132130
"jest-junit": "^16.0.0",
133131
"lint-staged": "^16.2.7",
134132
"np": "^10.3.0",
135133
"tailwindcss": "4.1.18",
136-
"ts-jest": "^29.4.6",
137134
"typescript": "^5.9.3"
138135
},
139136
"expo": {

0 commit comments

Comments
 (0)