-
-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update docs and tests for arktype
- Loading branch information
Showing
9 changed files
with
367 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
examples/react/search-validator-adapters/tests/arktype.test-d.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Link } from '@tanstack/react-router' | ||
import { expectTypeOf, test } from 'vitest' | ||
import { Route as ArkTypeRoute } from '../src/routes/users/arktype.index' | ||
import type { router } from '../src/main' | ||
|
||
test('infers correct input and output type for valibot', () => { | ||
expectTypeOf(Link<typeof router, string, '/users/arktype'>) | ||
.parameter(0) | ||
.toHaveProperty('search') | ||
.exclude<boolean | ((...args: ReadonlyArray<any>) => any)>() | ||
.toEqualTypeOf<{ search?: string } | undefined>() | ||
|
||
expectTypeOf(ArkTypeRoute.useSearch()).toEqualTypeOf<{ | ||
search: string | ||
}>() | ||
}) |
64 changes: 64 additions & 0 deletions
64
examples/react/search-validator-adapters/tests/arktype.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react' | ||
import { expect, test } from 'vitest' | ||
import { | ||
Link, | ||
RouterProvider, | ||
createRootRoute, | ||
createRoute, | ||
createRouter, | ||
} from '@tanstack/react-router' | ||
|
||
import '@testing-library/jest-dom/vitest' | ||
import { type } from 'arktype' | ||
|
||
test('can navigate to the route', async () => { | ||
const rootRoute = createRootRoute() | ||
|
||
const indexRoute = createRoute({ | ||
getParentRoute: () => rootRoute, | ||
path: '/', | ||
component: () => <Link to="/users/arktype">Arktype</Link>, | ||
}) | ||
|
||
const ArkType = () => { | ||
const { search } = arkTypeRoute.useSearch() | ||
|
||
return ( | ||
<div> | ||
<div>{search}</div> | ||
<Link from="/users/arktype" search={{ search: 'updated' }}> | ||
Update | ||
</Link> | ||
</div> | ||
) | ||
} | ||
|
||
const search = type({ | ||
'search?': 'string = "default"', | ||
}) | ||
|
||
const arkTypeRoute = createRoute({ | ||
getParentRoute: () => rootRoute, | ||
path: '/users/arkType', | ||
validateSearch: search, | ||
component: ArkType, | ||
}) | ||
|
||
const routeTree = rootRoute.addChildren([indexRoute, arkTypeRoute]) | ||
|
||
const router = createRouter({ routeTree }) | ||
|
||
render(<RouterProvider router={router as any} />) | ||
|
||
const link = await screen.findByText('Arktype') | ||
|
||
fireEvent.click(link) | ||
|
||
expect(await screen.findByText('default')).toBeInTheDocument() | ||
|
||
const updateLink = await screen.findByText('Update') | ||
|
||
fireEvent.click(updateLink) | ||
|
||
expect(await screen.findByText('updated')).toBeInTheDocument() | ||
}) |
5 changes: 2 additions & 3 deletions
5
examples/react/search-validator-adapters/tests/valibot.test-d.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
examples/react/search-validator-adapters/tests/valibot.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ | |
"react-dom": "^18.3.1", | ||
"redaxios": "^0.5.1", | ||
"rimraf": "^6.0.1", | ||
"typescript": "^5.6.2", | ||
"typescript": "^5.6.3", | ||
"typescript51": "npm:[email protected]", | ||
"typescript52": "npm:[email protected]", | ||
"typescript53": "npm:[email protected]", | ||
|
Oops, something went wrong.