Skip to content

Commit a8ea2b8

Browse files
ci: apply automated fixes
1 parent ecfe14b commit a8ea2b8

File tree

2 files changed

+40
-27
lines changed

2 files changed

+40
-27
lines changed

docs/router/framework/react/how-to/setup-testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ export function createAuthenticatedRouter(user = mockUser) {
882882
component: DashboardComponent,
883883
}),
884884
]
885-
885+
886886
return createTestRouter(protectedRoutes, {
887887
context: {
888888
auth: { user, isAuthenticated: true },

docs/router/framework/react/how-to/test-file-based-routing.md

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ export function renderWithFileRoutes(
123123
}
124124

125125
// Helper to test specific file routes
126-
export function createMockFileRoute(path: string, component: React.ComponentType) {
126+
export function createMockFileRoute(
127+
path: string,
128+
component: React.ComponentType,
129+
) {
127130
// This is useful for isolated testing when you don't want to use the full route tree
128131
return {
129132
path,
@@ -165,7 +168,7 @@ describe('Generated Route Tree', () => {
165168
}
166169

167170
const routePaths = getAllRoutePaths(routeTree)
168-
171+
169172
// Test that expected routes are present
170173
expect(routePaths).toContain('/')
171174
expect(routePaths).toContain('/about')
@@ -174,9 +177,11 @@ describe('Generated Route Tree', () => {
174177

175178
it('should have correct route hierarchy', () => {
176179
// Test parent-child relationships
177-
const homeRoute = routeTree.children?.find((child: any) => child.path === '/')
180+
const homeRoute = routeTree.children?.find(
181+
(child: any) => child.path === '/',
182+
)
178183
expect(homeRoute).toBeDefined()
179-
184+
180185
// Test for specific route structure based on your file organization
181186
// For example, if you have /posts/$postId routes:
182187
// const postsRoute = routeTree.children?.find((child: any) => child.path === '/posts')
@@ -415,7 +420,7 @@ describe('Programmatic Navigation', () => {
415420
await user.click(screen.getByRole('button', { name: /search/i }))
416421

417422
expect(router.state.location.search).toMatchObject({
418-
q: 'test query'
423+
q: 'test query',
419424
})
420425
})
421426
})
@@ -447,9 +452,9 @@ describe('File-Based Route Guards', () => {
447452
})
448453

449454
it('should allow authenticated users to access protected routes', () => {
450-
const mockAuth = {
451-
isAuthenticated: true,
452-
user: { id: '1', name: 'John' }
455+
const mockAuth = {
456+
isAuthenticated: true,
457+
user: { id: '1', name: 'John' },
453458
}
454459

455460
renderWithFileRoutes(<div />, {
@@ -475,12 +480,12 @@ describe('File-Based Route Loaders', () => {
475480
const mockFetchPost = vi.fn().mockResolvedValue({
476481
id: '123',
477482
title: 'Test Post',
478-
content: 'Test content'
483+
content: 'Test content',
479484
})
480485

481486
// If your route loader uses a global API function, mock it
482487
vi.mock('../api/posts', () => ({
483-
fetchPost: mockFetchPost
488+
fetchPost: mockFetchPost,
484489
}))
485490

486491
renderWithFileRoutes(<div />, {
@@ -498,7 +503,7 @@ describe('File-Based Route Loaders', () => {
498503
const mockFetchPost = vi.fn().mockRejectedValue(new Error('Post not found'))
499504

500505
vi.mock('../api/posts', () => ({
501-
fetchPost: mockFetchPost
506+
fetchPost: mockFetchPost,
502507
}))
503508

504509
renderWithFileRoutes(<div />, {
@@ -576,24 +581,26 @@ describe('File Route Error Handling', () => {
576581
Route: {
577582
component: () => {
578583
throw new Error('Test error')
579-
}
580-
}
584+
},
585+
},
581586
}))
582587

583588
renderWithFileRoutes(<div />, {
584589
initialLocation: '/error-prone',
585590
})
586591

587592
expect(screen.getByText(/Something went wrong/)).toBeInTheDocument()
588-
593+
589594
consoleSpy.mockRestore()
590595
})
591596

592597
it('should handle loader errors with error component', async () => {
593-
const mockFailingLoader = vi.fn().mockRejectedValue(new Error('Load failed'))
598+
const mockFailingLoader = vi
599+
.fn()
600+
.mockRejectedValue(new Error('Load failed'))
594601

595602
vi.mock('../api/data', () => ({
596-
loadData: mockFailingLoader
603+
loadData: mockFailingLoader,
597604
}))
598605

599606
renderWithFileRoutes(<div />, {
@@ -620,13 +627,13 @@ describe('Generated Route Types', () => {
620627
it('should provide type-safe navigation', () => {
621628
function TestComponent() {
622629
const navigate = useNavigate()
623-
630+
624631
const handleNavigate = () => {
625632
// This should be type-safe based on your generated routes
626633
navigate({
627634
to: '/posts/$postId',
628635
params: { postId: '123' },
629-
search: { tab: 'comments' }
636+
search: { tab: 'comments' },
630637
})
631638
}
632639

@@ -665,10 +672,10 @@ describe('Route Tree Development', () => {
665672
it('should regenerate routes when files change', () => {
666673
// This test ensures your route tree is properly generated
667674
// You can add specific assertions based on your file structure
668-
675+
669676
expect(routeTree).toBeDefined()
670677
expect(typeof routeTree.children).toBe('object')
671-
678+
672679
// Test specific routes exist
673680
const routes = getAllRouteIds(routeTree)
674681
expect(routes).toContain('/')
@@ -703,7 +710,9 @@ Create `e2e/file-routing.spec.ts`:
703710
import { test, expect } from '@playwright/test'
704711

705712
test.describe('File-Based Route E2E', () => {
706-
test('should navigate through file-based route structure', async ({ page }) => {
713+
test('should navigate through file-based route structure', async ({
714+
page,
715+
}) => {
707716
await page.goto('/')
708717

709718
// Test home route (from src/routes/index.tsx)
@@ -753,7 +762,7 @@ import { createFileRoute } from '@tanstack/react-router'
753762
export const createMockFileRoute = (
754763
path: string,
755764
component: React.ComponentType,
756-
options: any = {}
765+
options: any = {},
757766
) => {
758767
return createFileRoute(path)({
759768
component,
@@ -785,7 +794,7 @@ describe('Route Discovery', () => {
785794
it('should discover all routes from file structure', () => {
786795
// Test that your route tree includes all expected routes
787796
// This helps catch when routes are accidentally not being generated
788-
797+
789798
const expectedRoutes = [
790799
'/',
791800
'/about',
@@ -795,7 +804,7 @@ describe('Route Discovery', () => {
795804
'/dashboard/settings',
796805
]
797806

798-
expectedRoutes.forEach(routePath => {
807+
expectedRoutes.forEach((routePath) => {
799808
const routeExists = checkRouteExists(routeTree, routePath)
800809
expect(routeExists).toBe(true)
801810
})
@@ -844,7 +853,7 @@ describe('Posts Route (/posts)', () => {
844853
renderWithFileRoutes(<div />, {
845854
initialLocation: '/posts',
846855
})
847-
856+
848857
expect(screen.getByText(/Posts/)).toBeInTheDocument()
849858
})
850859

@@ -876,11 +885,13 @@ describe('Dashboard Routes', () => {
876885
### Common Issues
877886

878887
**Problem**: Route tree not found in tests
888+
879889
```bash
880890
Error: Cannot find module '../routeTree.gen'
881891
```
882892

883893
**Solution**: Ensure route tree generation in test setup:
894+
884895
```ts
885896
// vitest.config.ts
886897
export default defineConfig({
@@ -897,6 +908,7 @@ export default defineConfig({
897908
**Problem**: Routes not updating in tests after file changes
898909

899910
**Solution**: Clear module cache in test setup:
911+
900912
```ts
901913
// src/test/setup.ts
902914
beforeEach(() => {
@@ -909,6 +921,7 @@ beforeEach(() => {
909921
**Problem**: Type errors in tests with generated routes
910922

911923
**Solution**: Ensure proper TypeScript configuration:
924+
912925
```json
913926
{
914927
"compilerOptions": {
@@ -934,4 +947,4 @@ After setting up file-based route testing, you might want to:
934947
- [TanStack Router File-Based Routing](../routing/file-based-routing.md) - Complete file-based routing guide
935948
- [File Naming Conventions](../routing/file-naming-conventions.md) - Understanding file structure
936949
- [Testing Library](https://testing-library.com/) - Component testing utilities
937-
- [Vitest](https://vitest.dev/) - Testing framework documentation
950+
- [Vitest](https://vitest.dev/) - Testing framework documentation

0 commit comments

Comments
 (0)