@@ -17,7 +17,12 @@ import {
17
17
} from "../utils" ;
18
18
import { deferredData , trackedPromise } from "./utils/custom-matchers" ;
19
19
import { createDeferred } from "./utils/data-router-setup" ;
20
- import { createRequest , createSubmitRequest , invariant } from "./utils/utils" ;
20
+ import {
21
+ createRequest ,
22
+ createSubmitRequest ,
23
+ invariant ,
24
+ sleep ,
25
+ } from "./utils/utils" ;
21
26
22
27
interface CustomMatchers < R = jest . Expect > {
23
28
trackedPromise ( data ?: any , error ?: any , aborted ?: boolean ) : R ;
@@ -293,6 +298,74 @@ describe("ssr", () => {
293
298
} ) ;
294
299
} ) ;
295
300
301
+ it ( "should support route.lazy" , async ( ) => {
302
+ let { query } = createStaticHandler ( [
303
+ {
304
+ id : "root" ,
305
+ path : "/" ,
306
+ async lazy ( ) {
307
+ await sleep ( 100 ) ;
308
+ return {
309
+ async loader ( ) {
310
+ await sleep ( 100 ) ;
311
+ return "ROOT LOADER" ;
312
+ } ,
313
+ } ;
314
+ } ,
315
+ } ,
316
+ {
317
+ id : "parent" ,
318
+ path : "/parent" ,
319
+ async lazy ( ) {
320
+ await sleep ( 100 ) ;
321
+ return {
322
+ async loader ( ) {
323
+ await sleep ( 100 ) ;
324
+ return "PARENT LOADER" ;
325
+ } ,
326
+ } ;
327
+ } ,
328
+ children : [
329
+ {
330
+ id : "child" ,
331
+ path : "child" ,
332
+ async lazy ( ) {
333
+ await sleep ( 100 ) ;
334
+ return {
335
+ async loader ( ) {
336
+ await sleep ( 100 ) ;
337
+ return "CHILD LOADER" ;
338
+ } ,
339
+ } ;
340
+ } ,
341
+ } ,
342
+ ] ,
343
+ } ,
344
+ ] ) ;
345
+
346
+ let context = await query ( createRequest ( "/" ) ) ;
347
+ expect ( context ) . toMatchObject ( {
348
+ loaderData : {
349
+ root : "ROOT LOADER" ,
350
+ } ,
351
+ errors : null ,
352
+ location : { pathname : "/" } ,
353
+ matches : [ { route : { id : "root" } } ] ,
354
+ } ) ;
355
+
356
+ context = await query ( createRequest ( "/parent/child" ) ) ;
357
+ expect ( context ) . toMatchObject ( {
358
+ actionData : null ,
359
+ loaderData : {
360
+ parent : "PARENT LOADER" ,
361
+ child : "CHILD LOADER" ,
362
+ } ,
363
+ errors : null ,
364
+ location : { pathname : "/parent/child" } ,
365
+ matches : [ { route : { id : "parent" } } , { route : { id : "child" } } ] ,
366
+ } ) ;
367
+ } ) ;
368
+
296
369
it ( "should support document submit navigations" , async ( ) => {
297
370
let { query } = createStaticHandler ( SSR_ROUTES ) ;
298
371
let context = await query ( createSubmitRequest ( "/parent/child" ) ) ;
0 commit comments