Files
tuono/packages/tuono-router/tests/route.test.ts
T
2024-05-11 15:08:49 +02:00

29 lines
831 B
TypeScript

/* 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()
},
)
})