@@ -10286,6 +10286,20 @@ describe("a router", () => {
10286
10286
} ;
10287
10287
}
10288
10288
10289
+ it ( "should match routes automatically if no routeId is provided" , async ( ) => {
10290
+ let { queryRoute } = createStaticHandler ( SSR_ROUTES ) ;
10291
+ let data ;
10292
+
10293
+ data = await queryRoute ( createRequest ( "/parent" ) ) ;
10294
+ expect ( data ) . toBe ( "PARENT LOADER" ) ;
10295
+
10296
+ data = await queryRoute ( createRequest ( "/parent?index" ) ) ;
10297
+ expect ( data ) . toBe ( "PARENT INDEX LOADER" ) ;
10298
+
10299
+ data = await queryRoute ( createRequest ( "/parent/child" ) , "child" ) ;
10300
+ expect ( data ) . toBe ( "CHILD LOADER" ) ;
10301
+ } ) ;
10302
+
10289
10303
it ( "should support singular route load navigations (primitives)" , async ( ) => {
10290
10304
let { queryRoute } = createStaticHandler ( SSR_ROUTES ) ;
10291
10305
let data ;
@@ -10317,6 +10331,7 @@ describe("a router", () => {
10317
10331
} ) ;
10318
10332
10319
10333
it ( "should support singular route load navigations (Responses)" , async ( ) => {
10334
+ /* eslint-disable jest/no-conditional-expect */
10320
10335
let T = setupFlexRouteTest ( ) ;
10321
10336
let data ;
10322
10337
@@ -10329,9 +10344,13 @@ describe("a router", () => {
10329
10344
expect ( await data . text ( ) ) . toBe ( "Created!" ) ;
10330
10345
10331
10346
// Thrown Success Response
10332
- data = await T . rejectLoader ( new Response ( "Created!" , { status : 201 } ) ) ;
10333
- expect ( data . status ) . toBe ( 201 ) ;
10334
- expect ( await data . text ( ) ) . toBe ( "Created!" ) ;
10347
+ try {
10348
+ await T . rejectLoader ( new Response ( "Created!" , { status : 201 } ) ) ;
10349
+ expect ( false ) . toBe ( true ) ;
10350
+ } catch ( data ) {
10351
+ expect ( data . status ) . toBe ( 201 ) ;
10352
+ expect ( await data . text ( ) ) . toBe ( "Created!" ) ;
10353
+ }
10335
10354
10336
10355
// Returned Redirect Response
10337
10356
data = await T . resolveLoader (
@@ -10359,9 +10378,14 @@ describe("a router", () => {
10359
10378
expect ( await data . text ( ) ) . toBe ( "Why?" ) ;
10360
10379
10361
10380
// Thrown Error Response
10362
- data = await T . rejectLoader ( new Response ( "Oh no!" , { status : 401 } ) ) ;
10363
- expect ( data . status ) . toBe ( 401 ) ;
10364
- expect ( await data . text ( ) ) . toBe ( "Oh no!" ) ;
10381
+ try {
10382
+ await T . rejectLoader ( new Response ( "Oh no!" , { status : 401 } ) ) ;
10383
+ expect ( false ) . toBe ( true ) ;
10384
+ } catch ( data ) {
10385
+ expect ( data . status ) . toBe ( 401 ) ;
10386
+ expect ( await data . text ( ) ) . toBe ( "Oh no!" ) ;
10387
+ }
10388
+ /* eslint-enable jest/no-conditional-expect */
10365
10389
} ) ;
10366
10390
10367
10391
it ( "should support singular route load navigations (Errors)" , async ( ) => {
@@ -10445,6 +10469,7 @@ describe("a router", () => {
10445
10469
} ) ;
10446
10470
10447
10471
it ( "should support singular route submit navigations (Responses)" , async ( ) => {
10472
+ /* eslint-disable jest/no-conditional-expect */
10448
10473
let T = setupFlexRouteTest ( ) ;
10449
10474
let data ;
10450
10475
@@ -10457,9 +10482,13 @@ describe("a router", () => {
10457
10482
expect ( await data . text ( ) ) . toBe ( "Created!" ) ;
10458
10483
10459
10484
// Thrown Success Response
10460
- data = await T . rejectAction ( new Response ( "Created!" , { status : 201 } ) ) ;
10461
- expect ( data . status ) . toBe ( 201 ) ;
10462
- expect ( await data . text ( ) ) . toBe ( "Created!" ) ;
10485
+ try {
10486
+ await T . rejectAction ( new Response ( "Created!" , { status : 201 } ) ) ;
10487
+ expect ( false ) . toBe ( true ) ;
10488
+ } catch ( data ) {
10489
+ expect ( data . status ) . toBe ( 201 ) ;
10490
+ expect ( await data . text ( ) ) . toBe ( "Created!" ) ;
10491
+ }
10463
10492
10464
10493
// Returned Redirect Response
10465
10494
data = await T . resolveAction (
@@ -10487,9 +10516,14 @@ describe("a router", () => {
10487
10516
expect ( await data . text ( ) ) . toBe ( "Why?" ) ;
10488
10517
10489
10518
// Thrown Error Response
10490
- data = await T . rejectAction ( new Response ( "Oh no!" , { status : 401 } ) ) ;
10491
- expect ( data . status ) . toBe ( 401 ) ;
10492
- expect ( await data . text ( ) ) . toBe ( "Oh no!" ) ;
10519
+ try {
10520
+ await T . rejectAction ( new Response ( "Oh no!" , { status : 401 } ) ) ;
10521
+ expect ( false ) . toBe ( true ) ;
10522
+ } catch ( data ) {
10523
+ expect ( data . status ) . toBe ( 401 ) ;
10524
+ expect ( await data . text ( ) ) . toBe ( "Oh no!" ) ;
10525
+ }
10526
+ /* eslint-enable jest/no-conditional-expect */
10493
10527
} ) ;
10494
10528
10495
10529
it ( "should support singular route submit navigations (Errors)" , async ( ) => {
@@ -10650,19 +10684,78 @@ describe("a router", () => {
10650
10684
) ;
10651
10685
} ) ;
10652
10686
10687
+ it ( "should handle not found routes with a 404 Response" , async ( ) => {
10688
+ /* eslint-disable jest/no-conditional-expect */
10689
+ let { queryRoute } = createStaticHandler ( [
10690
+ {
10691
+ id : "root" ,
10692
+ path : "/" ,
10693
+ } ,
10694
+ ] ) ;
10695
+
10696
+ try {
10697
+ await queryRoute ( createRequest ( "/junk" ) ) ;
10698
+ expect ( false ) . toBe ( true ) ;
10699
+ } catch ( data ) {
10700
+ expect ( data instanceof Response ) . toBe ( true ) ;
10701
+ expect ( data . status ) . toBe ( 404 ) ;
10702
+ expect ( data . statusText ) . toBe ( "Not Found" ) ;
10703
+ expect ( data . headers . get ( "X-Remix-Router-Error" ) ) . toBe ( "yes" ) ;
10704
+ }
10705
+
10706
+ try {
10707
+ await queryRoute ( createRequest ( "/" ) , "junk" ) ;
10708
+ expect ( false ) . toBe ( true ) ;
10709
+ } catch ( data ) {
10710
+ expect ( data instanceof Response ) . toBe ( true ) ;
10711
+ expect ( data . status ) . toBe ( 404 ) ;
10712
+ expect ( data . statusText ) . toBe ( "Not Found" ) ;
10713
+ expect ( data . headers . get ( "X-Remix-Router-Error" ) ) . toBe ( "yes" ) ;
10714
+ }
10715
+
10716
+ try {
10717
+ await queryRoute ( createSubmitRequest ( "/junk" ) ) ;
10718
+ expect ( false ) . toBe ( true ) ;
10719
+ } catch ( data ) {
10720
+ expect ( data instanceof Response ) . toBe ( true ) ;
10721
+ expect ( data . status ) . toBe ( 404 ) ;
10722
+ expect ( data . statusText ) . toBe ( "Not Found" ) ;
10723
+ expect ( data . headers . get ( "X-Remix-Router-Error" ) ) . toBe ( "yes" ) ;
10724
+ }
10725
+
10726
+ try {
10727
+ await queryRoute ( createSubmitRequest ( "/" ) , "junk" ) ;
10728
+ expect ( false ) . toBe ( true ) ;
10729
+ } catch ( data ) {
10730
+ expect ( data instanceof Response ) . toBe ( true ) ;
10731
+ expect ( data . status ) . toBe ( 404 ) ;
10732
+ expect ( data . statusText ) . toBe ( "Not Found" ) ;
10733
+ expect ( data . headers . get ( "X-Remix-Router-Error" ) ) . toBe ( "yes" ) ;
10734
+ }
10735
+
10736
+ /* eslint-enable jest/no-conditional-expect */
10737
+ } ) ;
10738
+
10653
10739
it ( "should handle not found action submissions with a 405 Response" , async ( ) => {
10740
+ /* eslint-disable jest/no-conditional-expect */
10654
10741
let { queryRoute } = createStaticHandler ( [
10655
10742
{
10656
10743
id : "root" ,
10657
10744
path : "/" ,
10658
10745
} ,
10659
10746
] ) ;
10660
- let request = createSubmitRequest ( "/" ) ;
10661
- let data = await queryRoute ( request , "root" ) ;
10662
- expect ( data instanceof Response ) . toBe ( true ) ;
10663
- expect ( data . status ) . toBe ( 405 ) ;
10664
- expect ( data . statusText ) . toBe ( "Method Not Allowed" ) ;
10665
- expect ( await data . text ( ) ) . toBe ( "No action found for [/]" ) ;
10747
+
10748
+ try {
10749
+ await queryRoute ( createSubmitRequest ( "/" ) , "root" ) ;
10750
+ expect ( false ) . toBe ( true ) ;
10751
+ } catch ( data ) {
10752
+ expect ( data instanceof Response ) . toBe ( true ) ;
10753
+ expect ( data . status ) . toBe ( 405 ) ;
10754
+ expect ( data . statusText ) . toBe ( "Method Not Allowed" ) ;
10755
+ expect ( data . headers . get ( "X-Remix-Router-Error" ) ) . toBe ( "yes" ) ;
10756
+ expect ( await data . text ( ) ) . toBe ( "No action found for [/]" ) ;
10757
+ }
10758
+ /* eslint-enable jest/no-conditional-expect */
10666
10759
} ) ;
10667
10760
} ) ;
10668
10761
} ) ;
0 commit comments