Open History to see the last commit
1/* eslint-disable */
2import { afterEach, describe, it, expect, vi } from 'vitest'
3import {
4 getRouteApi,
5 createFileRoute,
6 createLazyRoute,
7 createLazyFileRoute,
8 LazyRoute,
9 AnyRoute,
10 FileRoute,
11} from '../src'
12β
13afterEach(() => {
14 vi.restoreAllMocks()
15})
16β
17describe('createFileRoute', () => {
18 it('creates a non-root route without a deprecation warning', () => {
19 const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
20 // @ts-expect-error
21 const route = createFileRoute('')({})
22β
23 expect(route.isRoot).toBe(false)
24 expect(warn).not.toHaveBeenCalled()
25 })
26β
27 it('keeps the deprecation warning for direct FileRoute usage', () => {
28 const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
29 // @ts-expect-error
30 const route = new FileRoute('').createRoute({})
31β
32 expect(route.isRoot).toBe(false)
33 expect(warn).toHaveBeenCalledOnce()
34 })
35})
36β
37describe('createFileRoute has the same hooks as getRouteApi', () => {
38 const routeApi = getRouteApi('foo')
39 const hookNames = Object.keys(routeApi).filter((key) => key.startsWith('use'))
40 // @ts-expect-error
41 const route = createFileRoute('')({})
42β
43 it.each(hookNames.map((name) => [name]))(
44 'should have the "%s" hook defined',
45 (hookName) => {
46 expect(route[hookName as keyof typeof route]).toBeDefined()
47 },
48 )
49})
50β
51describe('createLazyFileRoute has the same hooks as getRouteApi', () => {
52 const routeApi = getRouteApi('foo')
53 const hookNames = Object.keys(routeApi).filter((key) => key.startsWith('use'))
54 // @ts-expect-error
55 const route = createLazyFileRoute('')({})
56β
57 it.each(hookNames.map((name) => [name]))(
58 'should have the "%s" hook defined',
59 (hookName) => {
60 expect(route[hookName as keyof LazyRoute<any>]).toBeDefined()
61 },
62 )
63})
64β
65describe('createLazyRoute has the same hooks as getRouteApi', () => {
66 const routeApi = getRouteApi('foo')
67 const route = createLazyRoute({})({})
68 const hookNames = Object.keys(routeApi).filter((key) => key.startsWith('use'))
69β
70 it.each(hookNames.map((name) => [name]))(
71 'should have the "%s" hook defined',
72 (hookName) => {
73 expect(route[hookName as keyof LazyRoute<any>]).toBeDefined()
74 },
75 )
76})