|
| 1 | +import 'utilities/src/logger/mocks' |
| 2 | + |
| 3 | +import { chrome } from 'jest-chrome' |
| 4 | +import { AppearanceSettingType } from 'wallet/src/features/appearance/slice' |
| 5 | +import { TextEncoder, TextDecoder } from 'util'; |
| 6 | + |
| 7 | +process.env.IS_UNISWAP_EXTENSION = true |
| 8 | + |
| 9 | +global.TextEncoder = TextEncoder; |
| 10 | +global.TextDecoder = TextDecoder; |
| 11 | + |
| 12 | +const ignoreLogs = { |
| 13 | + error: [ |
| 14 | + // We need to use _persist property to ensure that the state is properly |
| 15 | + // rehydrated (https://github.com/Uniswap/universe/pull/7502/files#r1566259088) |
| 16 | + 'Unexpected key "_persist" found in previous state received by the reducer.' |
| 17 | + ] |
| 18 | +} |
| 19 | + |
| 20 | +// Ignore certain logs that are expected during tests. |
| 21 | +Object.entries(ignoreLogs).forEach(([method, messages]) => { |
| 22 | + const key = method |
| 23 | + const originalMethod = console[key] |
| 24 | + console[key] = ((...args) => { |
| 25 | + if (messages.some((message) => args.some((arg) => typeof arg === 'string' && arg.startsWith(message)))) { |
| 26 | + return |
| 27 | + } |
| 28 | + originalMethod(...args) |
| 29 | + }) |
| 30 | +}) |
| 31 | + |
| 32 | +globalThis.matchMedia = |
| 33 | + globalThis.matchMedia || |
| 34 | + ((query) => { |
| 35 | + const reducedMotion = query.match(/prefers-reduced-motion: ([a-zA-Z0-9-]+)/) |
| 36 | + |
| 37 | + return { |
| 38 | + // Needed for reanimated to disable reduced motion warning in tests |
| 39 | + matches: reducedMotion ? reducedMotion[1] === 'no-preference' : false, |
| 40 | + addListener: jest.fn(), |
| 41 | + addEventListener: jest.fn(), |
| 42 | + removeEventListener: jest.fn(), |
| 43 | + } |
| 44 | + }) |
| 45 | + |
| 46 | +require('react-native-reanimated').setUpTests() |
| 47 | + |
| 48 | +global.chrome = chrome |
| 49 | + |
| 50 | +jest.mock('src/app/navigation/utils', () => ({ |
| 51 | + useExtensionNavigation: () => ({ |
| 52 | + navigateTo: jest.fn(), |
| 53 | + navigateBack: jest.fn(), |
| 54 | + }) |
| 55 | +})) |
| 56 | + |
| 57 | +jest.mock('wallet/src/features/focus/useIsFocused', () => { |
| 58 | + return jest.fn().mockReturnValue(true) |
| 59 | +}) |
| 60 | + |
| 61 | +const mockAppearanceSetting = AppearanceSettingType.System |
| 62 | +jest.mock('wallet/src/features/appearance/hooks', () => { |
| 63 | + return { |
| 64 | + useCurrentAppearanceSetting: () => mockAppearanceSetting, |
| 65 | + } |
| 66 | +}) |
| 67 | +jest.mock('wallet/src/features/appearance/hooks', () => { |
| 68 | + return { |
| 69 | + useSelectedColorScheme: () => 'light', |
| 70 | + } |
| 71 | +}) |
0 commit comments