0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-16 19:38:07 +00:00

Compare commits

...

8 commits

Author SHA1 Message Date
Manuel Schiller
75637991a3 fix(router): reject notFoundRoute and explain not-found rejections
- Neither test router supports the deprecated `notFoundRoute` option. The
  option types declare it as `never`, and both functions throw when it is
  passed anyway. In `createIsolatedTestRouter` it rendered the app's
  not-found route after a navigation, and the root used it to catch a
  `notFound()` thrown by the element, which then crashed.
- When `params.parse` threw `notFound()`, `createIsolatedTestRouter`
  rejected with "is not matched", although the route was matched with a
  not-found. When `validateSearch` threw it, the router wraps it in a
  `SearchParamError` without a message, so the rejection had none. Both
  now name the route and the step that threw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 00:34:23 +01:00
Manuel Schiller
59120770a3 fix(router): address review of the route testing utilities
- initRouteTree initialises the whole tree every time, as a router does.
  It skipped a tree whose root already had an id, so a route added later
  with `addChildren` stayed uninitialised and an override for it was
  rejected as unknown.
- createIsolatedTestRouter also leaves out defaultNotFoundComponent. After
  the element navigated to a location without a route, the router
  rendered the app's not-found component.
- IsolatedRouteState<TRouteTree, TId> types `route` as `TId`; it accepted
  every route id. The ConstrainLiteral check, which keeps `rootRouteId`
  from widening during inference, moves to the options of
  createIsolatedTestRouter.
- The docs say where createTestRouter starts without `location`: at the
  current location of its history, which is `/` for the default memory
  history.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 00:04:03 +01:00
Manuel Schiller
e1bbf1da0b test(vue-router): add a route-testing e2e project
The same app and tests as `e2e/react-router/route-testing`, written with
Vue JSX: file-based routes with automatic code splitting, tested through
`@tanstack/vue-router/testing` with Vitest in jsdom, including type tests.

The Solid counterpart is held back: under pnpm, vite-plugin-solid injects
a jest-dom setup file into projects that do not depend on jest-dom,
because its check also searches the NODE_PATH that pnpm's bin shims set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 23:29:59 +01:00
Manuel Schiller
ec53e47fdc feat(router-core): move route testing into core, add Solid and Vue
`createTestRouterWith` and `createIsolatedTestRouterWith` in
`@tanstack/router-core/testing` take a framework's `createRouter` and
hold the whole implementation, together with the option types
`TestRouterOptions` and `IsolatedTestRouterOptions`.

`@tanstack/react-router/testing`, `@tanstack/solid-router/testing` and
`@tanstack/vue-router/testing` are thin typed wrappers around them. Only
the element under test differs: a React element, a function that
returns Solid JSX (Solid evaluates JSX right away), or a Vue vnode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 23:12:08 +01:00
Manuel Schiller
c85dc11628 feat(react-router): split route testing into two standalone functions
Drop the `createRouterTesting` factory and its injected `render`:

- `createTestRouter` takes the options of `createRouter`, plus
  `location` and `overrides`, and returns a router that has not loaded.
- `createIsolatedTestRouter` resolves to a loaded router that renders
  one element in one route. Its `loaderData` is one map by route id for
  the route and the routes above it.

Override keys named after route options (`beforeLoad`, `loader`,
`context`, components) now only take functions with the original's
signature; seeds are `loaderData` and `routeContext`. The root route is
addressed with `rootRouteId`, which `IsolatedRouteState` checks with
`ConstrainLiteral` so that TypeScript keeps its literal type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 22:58:36 +01:00
Manuel Schiller
a39b8635c1 docs(router): type-check route tests with Vitest
Vitest can type-check tests: with `typecheck.enabled` it runs `tsc` with
the project's tsconfig, and a type error in a test file fails the run.
Enable it in the setup example and say so instead of claiming that
`vitest run` never checks types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 22:29:19 +01:00
Manuel Schiller
070c10a34b docs(router): document the experimental route testing utilities
Add a Testing Routes guide for React, a `createRouterTesting` API page,
and links to them from the testing how-to guides. Both pages carry an
experimental note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 22:19:53 +01:00
Manuel Schiller
ca7e7130de feat(react-router): add experimental typed route testing utilities
Add `@tanstack/react-router/testing` with `createRouterTesting`, which
returns two helpers built from an app's route tree:

- `createTestRouter` creates a router over a copy of the tree. Routes run
  their own lifecycle unless a test replaces `context`, `beforeLoad`,
  `loader` or a component option by route id, or seeds the route's
  context or loader data.
- `renderInRoute` renders one element in one route. No lifecycle option
  runs, and the types require the params, search, context and loader
  data that the skipped options would have produced.

The framework-independent part lives in `@tanstack/router-core/testing`.
The new `e2e/react-router/route-testing` project uses the helpers for its
own tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 22:19:52 +01:00
71 changed files with 6111 additions and 4 deletions

149
pnpm-lock.yaml generated