no-route-file-tests
Whether a route file gets a unit test.
Agent checkAdvises by default
The rule
Agents read this text as written when they write and review code.
Never write a unit test for a route file under routes/. Test the screen the route renders instead.
A route file is thin wiring: guards, a loader and one screen. The screen's own tests and the end-to-end tests cover it.
Examples
The agent flags code like the incorrect example and accepts code like the correct one. Each example is a small repo, because this rule looks across files. It opens on the file that matters; the other files are the repo around it.
Incorrect
srcfeaturesissuesscreensroutes
import { describe, expect, test } from '@jest/globals';import { Route } from './issues.tsx';// Incorrect: a test of the wiring, which the end-to-end tests already walk.describe('issues route', () => {test('renders the issues screen', () => {expect(Route.options.component).toBeDefined();});});
Correct
srcfeaturesissuesqueriesscreenstypes
import { describe, expect, test } from '@jest/globals';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import { RouterProvider, createMemoryHistory, createRootRoute, createRoute, createRouter } from '@tanstack/react-router';import { render, screen } from '@testing-library/react';import type { Issue } from '../types/Issue.ts';import { issuesQueryOptions } from '../queries/issuesQueryOptions.ts';import { IssuesScreen } from './IssuesScreen.tsx';// Correct: the screen renders under a router whose one route is its own, with a// query client holding what the loader would have fetched.const setupIssuesScreen = ({ issues = [{ id: 1, title: 'Login fails' }] }: { issues?: Issue[] } = {}) => {const queryClient = new QueryClient();queryClient.setQueryData(issuesQueryOptions().queryKey, issues);const rootRoute = createRootRoute();const issuesRoute = createRoute({ getParentRoute: () => rootRoute, path: '/issues', component: IssuesScreen });const router = createRouter({ routeTree: rootRoute.addChildren([issuesRoute]), history: createMemoryHistory({ initialEntries: ['/issues'] }) });render(<QueryClientProvider client={queryClient}><RouterProvider router={router} /></QueryClientProvider>,);};describe('IssuesScreen', () => {test('lists each issue by title', async () => {setupIssuesScreen();const row = await screen.findByText('Login fails');expect(row).toBeInTheDocument();});});
Configure
- Block
"blocking"Stops a run when a file the run changed breaks the rule. - AdviseDefault
"advisory"Reports it and hands it to the refactor agent. Never stops a run. - Off
"off"Not checked. Use it when your own linter already enforces the rule.
Add this to your lightsout.config.json, then change the value.
{"standards-rule-settings": {"no-route-file-tests": "advisory"}}