Open History to see the last commit
1import { expect } from '@playwright/test'
2import combinateImport from 'combinate'
3import { test } from '@tanstack/router-e2e-utils'
4import { isSpaMode } from '../tests/utils/isSpaMode'
5β
6// somehow playwright does not correctly import default exports
7const combinate = (combinateImport as any).default as typeof combinateImport
8β
9test.use({
10 whitelistErrors: [
11 /Failed to load resource: the server responded with a status of 404/,
12 ],
13})
14test.describe('not-found', () => {
15 test(`global not found`, async ({ page }) => {
16 const response = await page.goto(`/this-page-does-not-exist/foo/bar`)
17β
18 expect(response?.status()).toBe(isSpaMode ? 200 : 404)
19β
20 await expect(
21 page.getByTestId('default-not-found-component'),
22 ).toBeInViewport()
23 })
24β
25 test.describe('throw notFound()', () => {
26 const navigationTestMatrix = combinate({
27 // TODO beforeLoad!
28 thrower: [/* 'beforeLoad',*/ 'loader'] as const,
29 preload: [false, true] as const,
30 })
31β
32 navigationTestMatrix.forEach(({ thrower, preload }) => {
33 test(`navigation: thrower: ${thrower}, preload: ${preload}`, async ({
34 page,
35 }) => {
36 await page.goto(
37 `/not-found/${preload === false ? '?preload=false' : ''}`,
38 )
39 const link = page.getByTestId(`via-${thrower}`)
40β
41 if (preload) {
42 await link.focus()
43 await new Promise((r) => setTimeout(r, 250))
44 }
45β
46 await link.click()
47β
48 await expect(
49 page.getByTestId(`via-${thrower}-notFound-component`),
50 ).toBeInViewport()
51β
52 await expect(
53 page.getByTestId(`via-${thrower}-route-component`),
54 ).not.toBeInViewport()
55 })
56 })
57 const directVisitTestMatrix = combinate({
58 // TODO beforeLoad!
59β
60 thrower: [/* 'beforeLoad',*/ 'loader'] as const,
61 })
62β
63 directVisitTestMatrix.forEach(({ thrower }) => {
64 test(`direct visit: thrower: ${thrower}`, async ({ page }) => {
65 await page.goto(`/not-found/via-${thrower}`)
66 await page.waitForLoadState('networkidle')
67 await expect(
68 page.getByTestId(`via-${thrower}-notFound-component`),
69 ).toBeInViewport()
70 await expect(
71 page.getByTestId(`via-${thrower}-route-component`),
72 ).not.toBeInViewport()
73 })
74 })
75 })
76})