Open History to see the last commit
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})