blob: 43d0a5727cd36fc914ec6bf9b96ef8b9fd396186 (
plain)
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
|
import {
afterEach,
beforeEach,
describe,
expect,
it,
jest,
} from '@jest/globals';
import { renderHook, waitFor } from '@testing-library/react';
import { wpThematicsFixture } from '../../../../tests/fixtures';
import { ROUTES } from '../../constants';
import { useThematic } from './use-thematic';
describe('useThematic', () => {
beforeEach(() => {
/* Not sure why it is needed, but without it Jest was complaining with
* `Jest worker encountered 4 child process exceptions`... Maybe because of
* useSWR? */
jest.useFakeTimers({
doNotFake: ['queueMicrotask'],
});
});
afterEach(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});
/* eslint-disable max-statements */
it('fetch the requested thematic', async () => {
const { result } = renderHook(() =>
useThematic(wpThematicsFixture[0].slug)
);
// Inaccurate assertions count because of waitFor...
//expect.assertions(8);
expect.hasAssertions();
expect(result.current.thematic).toBeUndefined();
expect(result.current.isError).toBe(false);
expect(result.current.isLoading).toBe(true);
expect(result.current.isValidating).toBe(true);
jest.advanceTimersToNextTimer();
await waitFor(() =>
expect(result.current.thematic?.slug).toBe(
`${ROUTES.THEMATICS}/${wpThematicsFixture[0].slug}`
)
);
expect(result.current.isError).toBe(false);
expect(result.current.isLoading).toBe(false);
expect(result.current.isValidating).toBe(false);
});
/* eslint-enable max-statements */
});
|