-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy patherrorPage.test.jsx
More file actions
77 lines (66 loc) · 2.11 KB
/
errorPage.test.jsx
File metadata and controls
77 lines (66 loc) · 2.11 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { render, screen } from '@testing-library/react';
describe('ErrorPage', () => {
const setupErrorPage = async (t, showErrorDetails, suffix = '') => {
t.mock.module('#site/components/Common/Button', {
defaultExport: ({ children, href }) => <a href={href}>{children}</a>,
});
t.mock.module('#site/layouts/GlowingBackdrop', {
defaultExport: ({ children }) => <main>{children}</main>,
});
t.mock.module('#site/next.constants.mjs', {
namedExports: {
SHOW_ERROR_DETAILS: showErrorDetails,
},
});
return import(`../app/[locale]/error.tsx${suffix}`);
};
it('renders technical details in preview environments', async t => {
const { default: ErrorPage } = await setupErrorPage(t, true);
render(
<ErrorPage
error={Object.assign(new Error('Preview deployment failed'), {
digest: 'abc123',
})}
/>
);
assert.equal(
screen.getByRole('heading').textContent,
'layouts.error.internalServerError.title'
);
assert.equal(
screen.getByRole('link').textContent,
'layouts.error.backToHome'
);
assert.equal(
screen.getByText('layouts.error.details').textContent,
'layouts.error.details'
);
assert.match(
screen.getByText(/Preview deployment failed/).textContent,
/Preview deployment failed/
);
assert.match(
screen.getByText(/digest: abc123/i).textContent,
/digest: abc123/i
);
});
it('hides technical details when the flag is disabled', async t => {
const { default: ErrorPage } = await setupErrorPage(
t,
false,
'?show-error-details-disabled'
);
render(
<ErrorPage
error={Object.assign(new Error('Production should stay generic'), {
digest: 'hidden123',
})}
/>
);
assert.equal(screen.queryByText('layouts.error.details'), null);
assert.equal(screen.queryByText(/Production should stay generic/), null);
assert.equal(screen.queryByText(/digest: hidden123/i), null);
});
});