Skip to content

Commit 594de4b

Browse files
evansmjShahanaFarooqui
authored andcommitted
Unit tests setup
1 parent e72643d commit 594de4b

File tree

6 files changed

+1668
-1209
lines changed

6 files changed

+1668
-1209
lines changed

apps/frontend/src/setupTests.ts

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,58 @@
11
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+
});
455

5-
jest.mock('react-router-dom', () => ({
6-
...jest.requireActual('react-router-dom'),
7-
useNavigate: jest.fn(),
8-
}));
56+
afterAll(() => {
57+
jest.restoreAllMocks();
58+
});

apps/frontend/src/utilities/test-use-http.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)