Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

error-normalization.spec.ts

35 lines1.4 KB

1import { expect } from '@playwright/test'
2import { test } from '@tanstack/router-e2e-utils'
3import { isSpaMode } from './utils/isSpaMode'
4import { isPrerender } from './utils/isPrerender'
5​
6test.skip(isSpaMode || isPrerender, 'Requires dynamic SSR')
7​
8test.use({
9 whitelistErrors: [
10 'Failed to load resource: the server responded with a status of 500',
11 ],
12})
13​
14test('normalizes errors during SSR, hydration, and client navigation', async ({
15 page,
16}) => {
17 const response = await page.goto('/error-normalization?kind=string')
18 expect(response?.status()).toBe(500)
19 const html = await response!.text()
20 expect(html).toContain('data-name="Error"')
21 expect(html).toContain('data-message="loader failure"')
22 expect(html).toContain('data-cause="loader failure"')
23​
24 const details = page.getByTestId('error-details')
25 await expect(details).toHaveAttribute('data-hydrated', 'true')
26 await expect(details).toHaveAttribute('data-name', 'Error')
27 await expect(details).toHaveAttribute('data-message', 'loader failure')
28 await expect(details).toHaveAttribute('data-cause', 'loader failure')
29​
30 await page.getByRole('link', { name: 'Throw null' }).click()
31 await expect(details).toHaveAttribute('data-hydrated', 'true')
32 await expect(details).toHaveAttribute('data-name', 'Error')
33 await expect(details).toHaveAttribute('data-message', 'Unknown error')
34 await expect(details).toHaveAttribute('data-cause', 'null')
35})