|
1 | 1 | /* eslint-disable max-classes-per-file */ |
2 | 2 | import * as core from '@actions/core'; |
3 | 3 | import '@shopify/flash-list/jestSetup'; |
| 4 | +import {useMemo} from 'react'; |
4 | 5 | import type * as RNAppLogs from 'react-native-app-logs'; |
| 6 | +import type {ReadDirItem} from 'react-native-fs'; |
5 | 7 | import 'react-native-gesture-handler/jestSetup'; |
6 | 8 | import type * as RNKeyboardController from 'react-native-keyboard-controller'; |
7 | 9 | import mockStorage from 'react-native-onyx/dist/storage/__mocks__'; |
@@ -69,6 +71,12 @@ jest.mock('react-native-fs', () => ({ |
69 | 71 | res(); |
70 | 72 | }), |
71 | 73 | ), |
| 74 | + readDir: jest.fn( |
| 75 | + () => |
| 76 | + new Promise<ReadDirItem[]>((res) => { |
| 77 | + res([]); |
| 78 | + }), |
| 79 | + ), |
72 | 80 | CachesDirectoryPath: jest.fn(), |
73 | 81 | })); |
74 | 82 |
|
@@ -135,60 +143,70 @@ jest.mock('../modules/hybrid-app/src/NativeReactNativeHybridApp', () => ({ |
135 | 143 | clearOldDotAfterSignOut: jest.fn(), |
136 | 144 | })); |
137 | 145 |
|
| 146 | +const mockUseMemo = useMemo; |
| 147 | + |
138 | 148 | // Mock lazy asset loading to be synchronous in tests |
139 | 149 | jest.mock('../src/hooks/useLazyAsset.ts', () => ({ |
140 | | - useMemoizedLazyAsset: jest.fn(() => { |
141 | | - // Return a mock asset immediately to avoid async loading in tests |
142 | | - const mockAsset = { |
143 | | - src: 'mock-icon', |
144 | | - testID: 'mock-asset', |
145 | | - // Add common icon properties that tests might expect |
146 | | - height: 20, |
147 | | - width: 20, |
148 | | - }; |
149 | | - |
150 | | - return { |
151 | | - asset: mockAsset, |
152 | | - isLoaded: true, |
153 | | - isLoading: false, |
154 | | - hasError: false, |
155 | | - }; |
156 | | - }), |
157 | | - useMemoizedLazyIllustrations: jest.fn((names: readonly string[]) => { |
158 | | - // Return a Record with all requested illustration names |
159 | | - const mockIllustrations: Record<string, unknown> = {}; |
160 | | - for (const name of names) { |
161 | | - mockIllustrations[name] = { |
162 | | - src: `mock-${name}`, |
163 | | - testID: `mock-illustration-${name}`, |
| 150 | + useMemoizedLazyAsset: jest.fn((importFn) => |
| 151 | + mockUseMemo(() => { |
| 152 | + // Return a mock asset immediately to avoid async loading in tests |
| 153 | + const mockAsset = { |
| 154 | + src: 'mock-icon', |
| 155 | + testID: 'mock-asset', |
| 156 | + // Add common icon properties that tests might expect |
164 | 157 | height: 20, |
165 | 158 | width: 20, |
166 | 159 | }; |
167 | | - } |
168 | | - return mockIllustrations; |
169 | | - }), |
170 | | - useMemoizedLazyExpensifyIcons: jest.fn((names: readonly string[]) => { |
171 | | - // Return a Record with all requested icon names |
172 | | - const mockIcons: Record<string, unknown> = {}; |
173 | | - for (const name of names) { |
174 | | - mockIcons[name] = { |
175 | | - src: `mock-${name}`, |
176 | | - testID: `mock-expensify-icon-${name}`, |
177 | | - height: 20, |
178 | | - width: 20, |
| 160 | + |
| 161 | + return { |
| 162 | + asset: mockAsset, |
| 163 | + isLoaded: true, |
| 164 | + isLoading: false, |
| 165 | + hasError: false, |
179 | 166 | }; |
180 | | - } |
181 | | - return mockIcons; |
182 | | - }), |
183 | | - default: jest.fn(() => { |
184 | | - const mockAsset = {src: 'mock-icon', testID: 'mock-asset'}; |
185 | | - return { |
186 | | - asset: mockAsset, |
187 | | - isLoaded: true, |
188 | | - isLoading: false, |
189 | | - hasError: false, |
190 | | - }; |
191 | | - }), |
| 167 | + }, [importFn]), |
| 168 | + ), |
| 169 | + useMemoizedLazyIllustrations: jest.fn((names: readonly string[]) => |
| 170 | + mockUseMemo(() => { |
| 171 | + // Return a Record with all requested illustration names |
| 172 | + const mockIllustrations: Record<string, unknown> = {}; |
| 173 | + for (const name of names) { |
| 174 | + mockIllustrations[name] = { |
| 175 | + src: `mock-${name}`, |
| 176 | + testID: `mock-illustration-${name}`, |
| 177 | + height: 20, |
| 178 | + width: 20, |
| 179 | + }; |
| 180 | + } |
| 181 | + return mockIllustrations; |
| 182 | + }, [names]), |
| 183 | + ), |
| 184 | + useMemoizedLazyExpensifyIcons: jest.fn((names: readonly string[]) => |
| 185 | + mockUseMemo(() => { |
| 186 | + // Return a Record with all requested icon names |
| 187 | + const mockIcons: Record<string, unknown> = {}; |
| 188 | + for (const name of names) { |
| 189 | + mockIcons[name] = { |
| 190 | + src: `mock-${name}`, |
| 191 | + testID: `mock-expensify-icon-${name}`, |
| 192 | + height: 20, |
| 193 | + width: 20, |
| 194 | + }; |
| 195 | + } |
| 196 | + return mockIcons; |
| 197 | + }, [names]), |
| 198 | + ), |
| 199 | + default: jest.fn((importFn) => |
| 200 | + mockUseMemo(() => { |
| 201 | + const mockAsset = {src: 'mock-icon', testID: 'mock-asset'}; |
| 202 | + return { |
| 203 | + asset: mockAsset, |
| 204 | + isLoaded: true, |
| 205 | + isLoading: false, |
| 206 | + hasError: false, |
| 207 | + }; |
| 208 | + }, [importFn]), |
| 209 | + ), |
192 | 210 | })); |
193 | 211 |
|
194 | 212 | // Mock icon loading functions to resolve immediately |
|
0 commit comments