|
1 | 1 | import '@testing-library/jest-dom';
|
2 |
| -import '@testing-library/jest-dom'; |
3 |
| -jest.mock('./hooks/use-http.ts', () => require('./utilities/test-use-http.tsx')); |
| 2 | +import { spyOnBKPRGetAccountEvents, spyOnBKPRGetSatsFlow, spyOnBKPRGetVolume, spyOnGetInfo, spyOnListChannels, spyOnListFunds, spyOnListNodes, spyOnListPeers } from './utilities/test-utilities/mockService'; |
| 3 | + |
| 4 | +let mockedLocation = { |
| 5 | + pathname: '/', |
| 6 | + search: '', |
| 7 | + hash: '', |
| 8 | + state: null, |
| 9 | + key: 'default', |
| 10 | +}; |
| 11 | + |
| 12 | +jest.mock('react-router-dom', () => { |
| 13 | + const actual = jest.requireActual('react-router-dom'); |
| 14 | + return { |
| 15 | + ...actual, |
| 16 | + useNavigate: () => jest.fn(), |
| 17 | + useLocation: () => mockedLocation, |
| 18 | + }; |
| 19 | +}); |
| 20 | + |
| 21 | +export const setMockedLocation = (location: Partial<Location>) => { |
| 22 | + mockedLocation = { ...mockedLocation, ...location }; |
| 23 | +}; |
| 24 | + |
| 25 | +beforeEach(() => { |
| 26 | + jest.useFakeTimers(); |
| 27 | + spyOnGetInfo(); |
| 28 | + spyOnListNodes(); |
| 29 | + spyOnListChannels(); |
| 30 | + spyOnListPeers(); |
| 31 | + spyOnListFunds(); |
| 32 | + spyOnBKPRGetAccountEvents(); |
| 33 | + spyOnBKPRGetSatsFlow(); |
| 34 | + spyOnBKPRGetVolume(); |
| 35 | + const originalConsoleWarning = console.warn; |
| 36 | + jest.spyOn(console, 'warn').mockImplementation((msg, ...args) => { |
| 37 | + if ( |
| 38 | + typeof msg === 'string' && |
| 39 | + msg.includes('React Router Future Flag Warning: React Router will begin wrapping state updates in `React.startTransition` in v7') |
| 40 | + ) { |
| 41 | + return; |
| 42 | + } |
| 43 | + originalConsoleWarning(msg, ...args); |
| 44 | + }); |
| 45 | +}); |
| 46 | + |
| 47 | +afterEach(() => { |
| 48 | + jest.useRealTimers(); |
| 49 | + jest.restoreAllMocks(); |
| 50 | +}); |
| 51 | + |
| 52 | +beforeAll(() => { |
| 53 | + window.scrollTo = jest.fn(); |
| 54 | +}); |
4 | 55 |
|
5 |
| -jest.mock('react-router-dom', () => ({ |
6 |
| - ...jest.requireActual('react-router-dom'), |
7 |
| - useNavigate: jest.fn(), |
8 |
| -})); |
| 56 | +afterAll(() => { |
| 57 | + jest.restoreAllMocks(); |
| 58 | +}); |
0 commit comments