Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

RouterProvider.test.tsx

37 lines1.1 KB

1import { describe, expect, it } from 'vitest'
2import { render } from '@solidjs/testing-library'
3import { createContext, useContext } from 'solid-js'
4import { createRootRoute, createRouter } from '../src'
5import { RouterProvider } from '../src/RouterProvider'
6​
7describe('RouterProvider', () => {
8 it('should provide context through RouterProvider Wrap', async () => {
9 const ctx = createContext<string>()
10​
11 const rootRoute = createRootRoute({
12 component: () => {
13 const contextValue = useContext(ctx)
14 expect(contextValue, 'Context is not provided').not.toBeUndefined()
15​
16 return <div>{contextValue}</div>
17 },
18 })
19​
20 const routeTree = rootRoute.addChildren([])
21 const router = createRouter({
22 routeTree,
23 })
24​
25 const app = render(() => (
26 <RouterProvider
27 router={router}
28 Wrap={(props) => {
29 return <ctx.Provider value={'findMe'}>{props.children}</ctx.Provider>
30 }}
31 />
32 ))
33​
34 const indexElem = await app.findByText('findMe')
35 expect(indexElem).toBeInTheDocument()
36 })
37})