-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathOops.test.tsx
More file actions
58 lines (44 loc) · 1.58 KB
/
Oops.test.tsx
File metadata and controls
58 lines (44 loc) · 1.58 KB
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
58
import { act, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { PersonIcon } from '@primer/octicons-react';
import { navigateMock, renderWithAppContext } from '../__helpers__/test-utils';
import { Oops } from './Oops';
describe('renderer/components/Oops.tsx', () => {
it('should render itself & its children - specified error', async () => {
const mockError = {
title: 'Error title',
descriptions: ['Error description'],
emojis: ['🔥'],
};
let tree: ReturnType<typeof renderWithAppContext> | null = null;
await act(async () => {
tree = renderWithAppContext(<Oops error={mockError} />);
});
expect(tree.container).toMatchSnapshot();
});
it('should render itself & its children - fallback to unknown error', async () => {
let tree: ReturnType<typeof renderWithAppContext> | null = null;
await act(async () => {
tree = renderWithAppContext(<Oops error={null} />);
});
expect(tree.container).toMatchSnapshot();
});
it('should render action buttons and navigate on click', async () => {
const mockError = {
title: 'Error title',
descriptions: ['Error description'],
emojis: ['🔥'],
actions: [
{
label: 'Go somewhere',
route: '/somewhere',
variant: 'danger' as const,
icon: PersonIcon,
},
],
};
renderWithAppContext(<Oops error={mockError} />);
await userEvent.click(screen.getByText('Go somewhere'));
expect(navigateMock).toHaveBeenCalledWith('/somewhere');
});
});