11import { expect , test } from 'vitest'
22import { fireEvent , render , screen } from '@solidjs/testing-library'
3- import { createContext , useContext } from 'solid-js'
43import {
54 Link ,
65 Outlet ,
76 RouterProvider ,
8- createMemoryHistory ,
97 createRootRoute ,
108 createRoute ,
119 createRouter ,
1210 isMatch ,
1311 useMatches ,
1412} from '../src'
15- import { sleep } from './utils'
1613
1714const rootRoute = createRootRoute ( )
1815
@@ -33,7 +30,6 @@ const invoicesRoute = createRoute({
3330
3431const InvoicesIndex = ( ) => {
3532 const matches = useMatches < DefaultRouter > ( )
36- console . log ( 'Matchse' , matches ( ) )
3733
3834 const loaderDataMatches = matches ( ) . filter ( ( match ) =>
3935 isMatch ( match , 'loaderData.0.id' ) ,
@@ -126,102 +122,6 @@ test('when filtering useMatches by loaderData', async () => {
126122 expect ( await screen . findByText ( 'Incorrect Matches -' ) ) . toBeInTheDocument ( )
127123} )
128124
129- test ( 'Matches provides InnerWrap context to route components' , async ( ) => {
130- const rootRoute = createRootRoute ( {
131- component : ( ) => {
132- const contextValue = useContext ( ctx )
133- expect ( contextValue , 'Context is not provided' ) . not . toBeUndefined ( )
134-
135- return < div > { contextValue } </ div >
136- } ,
137- } )
138-
139- const routeTree = rootRoute . addChildren ( [ ] )
140- const router = createRouter ( {
141- routeTree,
142- } )
143-
144- const ctx = createContext < string > ( )
145-
146- const app = render ( ( ) => (
147- < RouterProvider
148- router = { router }
149- InnerWrap = { ( props ) => {
150- return (
151- < ctx . Provider value = { 'context-for-children' } >
152- { props . children }
153- </ ctx . Provider >
154- )
155- } }
156- />
157- ) )
158-
159- const indexElem = await app . findByText ( 'context-for-children' )
160- expect ( indexElem ) . toBeInTheDocument ( )
161- } )
162-
163- test ( 'Matches provides InnerWrap context to defaultPendingComponent' , async ( ) => {
164- const rootRoute = createRootRoute ( { } )
165- const indexRoute = createRoute ( {
166- getParentRoute : ( ) => rootRoute ,
167- path : '/' ,
168- component : ( ) => {
169- return (
170- < div >
171- < Link to = "/home" > link to home</ Link >
172- </ div >
173- )
174- } ,
175- } )
176-
177- const homeRoute = createRoute ( {
178- getParentRoute : ( ) => rootRoute ,
179- path : '/home' ,
180- loader : ( ) => sleep ( 300 ) ,
181- component : ( ) => < div > Home page</ div > ,
182- } )
183-
184- const routeTree = rootRoute . addChildren ( [ homeRoute , indexRoute ] )
185- const router = createRouter ( {
186- routeTree,
187- history : createMemoryHistory ( {
188- initialEntries : [ '/' ] ,
189- } ) ,
190- } )
191-
192- const ctx = createContext < string > ( )
193-
194- const app = render ( ( ) => (
195- < RouterProvider
196- router = { router }
197- defaultPendingMs = { 200 }
198- defaultPendingComponent = { ( ) => {
199- const contextValue = useContext ( ctx )
200- expect ( contextValue , 'Context is not provided' ) . not . toBeUndefined ( )
201-
202- return < div > { contextValue } </ div >
203- } }
204- InnerWrap = { ( props ) => {
205- return (
206- < ctx . Provider value = { 'context-for-default-pending' } >
207- { props . children }
208- </ ctx . Provider >
209- )
210- } }
211- />
212- ) )
213-
214- const linkToHome = await app . findByRole ( 'link' , {
215- name : 'link to home' ,
216- } )
217- expect ( linkToHome ) . toBeInTheDocument ( )
218-
219- fireEvent . click ( linkToHome )
220-
221- const indexElem = await app . findByText ( 'context-for-default-pending' )
222- expect ( indexElem ) . toBeInTheDocument ( )
223- } )
224-
225125test ( 'should show pendingComponent of root route' , async ( ) => {
226126 const root = createRootRoute ( {
227127 pendingComponent : ( ) => < div data-testId = "root-pending" /> ,
@@ -230,7 +130,6 @@ test('should show pendingComponent of root route', async () => {
230130 } ,
231131 component : ( ) => < div data-testId = "root-content" /> ,
232132 } )
233-
234133 const router = createRouter ( {
235134 routeTree : root ,
236135 defaultPendingMs : 0 ,
0 commit comments