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