-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.spec.tsx
57 lines (46 loc) · 1.5 KB
/
App.spec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React, { StrictMode } from 'react';
import { render, screen } from '@testing-library/react';
import { Provider } from 'react-redux';
import { setUpStore } from '@/store';
import { createHandlers } from '@/_mocks/handlers';
import App from '../App';
import { mswTestServer } from './__setup__';
function setUpApp() {
mswTestServer.use(...createHandlers());
const store = setUpStore();
render(
<StrictMode>
<Provider store={store}>
<App />
</Provider>
</StrictMode>
);
}
describe('App test', () => {
it('Loads a project without fake timers', async () => {
// [SETUP] - set up app
setUpApp();
// [ASSERT] - eventually loads projects
screen.getByText(/projects:/i);
await screen.findByText(/Successfully fetched projects!/i);
await screen.findByText(/2021-04-01/i);
});
it('Loads a project with jest fake timers (legacy)', async () => {
jest.useFakeTimers('legacy');
// [SETUP] - set up app
setUpApp();
// [ASSERT] - eventually loads projects
screen.getByText(/projects:/i);
await screen.findByText(/Successfully fetched projects!/i);
await screen.findByText(/2021-04-01/i);
});
it('Loads a project with jest fake timers (modern)', async () => {
jest.useFakeTimers('modern');
// [SETUP] - set up app
setUpApp();
// [ASSERT] - eventually loads projects
screen.getByText(/projects:/i);
await screen.findByText(/Successfully fetched projects!/i);
await screen.findByText(/2021-04-01/i);
});
});