mirror of
https://github.com/tuono-labs/tuono
synced 2026-07-29 13:52:46 -07:00
feat: create basic router
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { expectTypeOf, test } from 'vitest'
|
||||
import {
|
||||
RouterProvider,
|
||||
createRootRoute,
|
||||
createRoute,
|
||||
createRouter,
|
||||
} from '../../src'
|
||||
|
||||
const rootRoute = createRootRoute()
|
||||
|
||||
const indexRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: '/',
|
||||
})
|
||||
|
||||
const invoicesRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: '/invoices',
|
||||
})
|
||||
|
||||
const routeTree = rootRoute.addChildren([invoicesRoute, indexRoute])
|
||||
|
||||
const defaultRouter = createRouter({
|
||||
routeTree,
|
||||
})
|
||||
|
||||
type DefaultRouter = typeof defaultRouter
|
||||
|
||||
test('can pass default router to the provider', () => {
|
||||
expectTypeOf(RouterProvider).parameter(0).toMatchTypeOf<{
|
||||
router: DefaultRouter
|
||||
routeTree?: DefaultRouter['routeTree']
|
||||
}>()
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
/* eslint-disable */
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { getRouteApi, createRoute } from '../src'
|
||||
|
||||
describe('getRouteApi', () => {
|
||||
it('should have the useRouteContext hook', () => {
|
||||
const api = getRouteApi('foo')
|
||||
expect(api.useRouteContext).toBeDefined()
|
||||
})
|
||||
|
||||
it('should have the useParams hook', () => {
|
||||
const api = getRouteApi('foo')
|
||||
expect(api.useParams).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('createRoute has the same hooks as getRouteApi', () => {
|
||||
const routeApi = getRouteApi('foo')
|
||||
const hookNames = Object.keys(routeApi).filter((key) => key.startsWith('use'))
|
||||
const route = createRoute({} as any)
|
||||
|
||||
it.each(hookNames.map((name) => [name]))(
|
||||
'should have the "%s" hook defined',
|
||||
(hookName) => {
|
||||
expect(route[hookName as keyof typeof route]).toBeDefined()
|
||||
},
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user