@@ -52,19 +52,101 @@ describe('extractRoutesAndCreateRouteTree', () => {
5252 ] ) ;
5353 } ) ;
5454
55- it ( 'should handle invalid route configuration path' , async ( ) => {
56- setAngularAppTestingManifest (
57- [ { path : 'home' , component : DummyComponent } ] ,
58- [
59- // This path starts with a slash, which should trigger an error
60- { path : '/invalid' , renderMode : RenderMode . Client } ,
61- ] ,
62- ) ;
55+ describe ( 'route configuration validation' , ( ) => {
56+ it ( `should error when a route starts with a '/'` , async ( ) => {
57+ setAngularAppTestingManifest (
58+ [ { path : 'home' , component : DummyComponent } ] ,
59+ [
60+ // This path starts with a slash, which should trigger an error
61+ { path : '/invalid' , renderMode : RenderMode . Client } ,
62+ ] ,
63+ ) ;
6364
64- const { errors } = await extractRoutesAndCreateRouteTree ( { url } ) ;
65- expect ( errors [ 0 ] ) . toContain (
66- `Invalid '/invalid' route configuration: the path cannot start with a slash.` ,
67- ) ;
65+ const { errors } = await extractRoutesAndCreateRouteTree ( { url } ) ;
66+ expect ( errors [ 0 ] ) . toContain (
67+ `Invalid '/invalid' route configuration: the path cannot start with a slash.` ,
68+ ) ;
69+ } ) ;
70+
71+ it ( "should error when 'getPrerenderParams' is used with a '**' route" , async ( ) => {
72+ setAngularAppTestingManifest (
73+ [ { path : 'home' , component : DummyComponent } ] ,
74+ [
75+ {
76+ path : '**' ,
77+ renderMode : RenderMode . Prerender ,
78+ getPrerenderParams ( ) {
79+ return Promise . resolve ( [ ] ) ;
80+ } ,
81+ } ,
82+ ] ,
83+ ) ;
84+
85+ const { errors } = await extractRoutesAndCreateRouteTree ( { url } ) ;
86+ expect ( errors [ 0 ] ) . toContain (
87+ "Invalid '**' route configuration: 'getPrerenderParams' cannot be used with a '**' route." ,
88+ ) ;
89+ } ) ;
90+
91+ it ( `should not error when a catch-all route didn't match any Angular route.` , async ( ) => {
92+ setAngularAppTestingManifest (
93+ [ { path : 'home' , component : DummyComponent } ] ,
94+ [
95+ { path : 'home' , renderMode : RenderMode . Server } ,
96+ { path : '**' , renderMode : RenderMode . Server } ,
97+ ] ,
98+ ) ;
99+
100+ const { errors } = await extractRoutesAndCreateRouteTree ( {
101+ url,
102+ invokeGetPrerenderParams : false ,
103+ includePrerenderFallbackRoutes : false ,
104+ } ) ;
105+
106+ expect ( errors ) . toHaveSize ( 0 ) ;
107+ } ) ;
108+
109+ it ( 'should error when a route is not defined in the server routing configuration' , async ( ) => {
110+ setAngularAppTestingManifest (
111+ [ { path : 'home' , component : DummyComponent } ] ,
112+ [
113+ { path : 'home' , renderMode : RenderMode . Server } ,
114+ { path : 'invalid' , renderMode : RenderMode . Server } ,
115+ ] ,
116+ ) ;
117+
118+ const { errors } = await extractRoutesAndCreateRouteTree ( {
119+ url,
120+ invokeGetPrerenderParams : false ,
121+ includePrerenderFallbackRoutes : false ,
122+ } ) ;
123+
124+ expect ( errors ) . toHaveSize ( 1 ) ;
125+ expect ( errors [ 0 ] ) . toContain (
126+ `The 'invalid' server route does not match any routes defined in the Angular routing configuration` ,
127+ ) ;
128+ } ) ;
129+
130+ it ( 'should error when a server route is not defined in the Angular routing configuration' , async ( ) => {
131+ setAngularAppTestingManifest (
132+ [
133+ { path : 'home' , component : DummyComponent } ,
134+ { path : 'invalid' , component : DummyComponent } ,
135+ ] ,
136+ [ { path : 'home' , renderMode : RenderMode . Server } ] ,
137+ ) ;
138+
139+ const { errors } = await extractRoutesAndCreateRouteTree ( {
140+ url,
141+ invokeGetPrerenderParams : false ,
142+ includePrerenderFallbackRoutes : false ,
143+ } ) ;
144+
145+ expect ( errors ) . toHaveSize ( 1 ) ;
146+ expect ( errors [ 0 ] ) . toContain (
147+ `The 'invalid' route does not match any route defined in the server routing configuration` ,
148+ ) ;
149+ } ) ;
68150 } ) ;
69151
70152 describe ( 'when `invokeGetPrerenderParams` is true' , ( ) => {
@@ -207,6 +289,13 @@ describe('extractRoutesAndCreateRouteTree', () => {
207289 return [ { param : 'some' } ] ;
208290 } ,
209291 } ,
292+ {
293+ path : ':param/*' ,
294+ renderMode : RenderMode . Prerender ,
295+ async getPrerenderParams ( ) {
296+ return [ { param : 'some' } ] ;
297+ } ,
298+ } ,
210299 { path : '**' , renderMode : RenderMode . Prerender } ,
211300 ] ,
212301 ) ;
@@ -216,6 +305,7 @@ describe('extractRoutesAndCreateRouteTree', () => {
216305 invokeGetPrerenderParams : true ,
217306 includePrerenderFallbackRoutes : true ,
218307 } ) ;
308+
219309 expect ( errors ) . toHaveSize ( 0 ) ;
220310 expect ( routeTree . toObject ( ) ) . toEqual ( [
221311 { route : '/' , renderMode : RenderMode . Prerender , redirectTo : '/some' } ,
@@ -318,7 +408,6 @@ describe('extractRoutesAndCreateRouteTree', () => {
318408
319409 const { routeTree, errors } = await extractRoutesAndCreateRouteTree ( {
320410 url,
321-
322411 invokeGetPrerenderParams : true ,
323412 includePrerenderFallbackRoutes : false ,
324413 } ) ;
@@ -374,66 +463,6 @@ describe('extractRoutesAndCreateRouteTree', () => {
374463 ] ) ;
375464 } ) ;
376465
377- it ( `should not error when a catch-all route didn't match any Angular route.` , async ( ) => {
378- setAngularAppTestingManifest (
379- [ { path : 'home' , component : DummyComponent } ] ,
380- [
381- { path : 'home' , renderMode : RenderMode . Server } ,
382- { path : '**' , renderMode : RenderMode . Server } ,
383- ] ,
384- ) ;
385-
386- const { errors } = await extractRoutesAndCreateRouteTree ( {
387- url,
388- invokeGetPrerenderParams : false ,
389- includePrerenderFallbackRoutes : false ,
390- } ) ;
391-
392- expect ( errors ) . toHaveSize ( 0 ) ;
393- } ) ;
394-
395- it ( 'should error when a route is not defined in the server routing configuration' , async ( ) => {
396- setAngularAppTestingManifest (
397- [ { path : 'home' , component : DummyComponent } ] ,
398- [
399- { path : 'home' , renderMode : RenderMode . Server } ,
400- { path : 'invalid' , renderMode : RenderMode . Server } ,
401- ] ,
402- ) ;
403-
404- const { errors } = await extractRoutesAndCreateRouteTree ( {
405- url,
406- invokeGetPrerenderParams : false ,
407- includePrerenderFallbackRoutes : false ,
408- } ) ;
409-
410- expect ( errors ) . toHaveSize ( 1 ) ;
411- expect ( errors [ 0 ] ) . toContain (
412- `The 'invalid' server route does not match any routes defined in the Angular routing configuration` ,
413- ) ;
414- } ) ;
415-
416- it ( 'should error when a server route is not defined in the Angular routing configuration' , async ( ) => {
417- setAngularAppTestingManifest (
418- [
419- { path : 'home' , component : DummyComponent } ,
420- { path : 'invalid' , component : DummyComponent } ,
421- ] ,
422- [ { path : 'home' , renderMode : RenderMode . Server } ] ,
423- ) ;
424-
425- const { errors } = await extractRoutesAndCreateRouteTree ( {
426- url,
427- invokeGetPrerenderParams : false ,
428- includePrerenderFallbackRoutes : false ,
429- } ) ;
430-
431- expect ( errors ) . toHaveSize ( 1 ) ;
432- expect ( errors [ 0 ] ) . toContain (
433- `The 'invalid' route does not match any route defined in the server routing configuration` ,
434- ) ;
435- } ) ;
436-
437466 it ( 'should use wildcard configuration when no Angular routes are defined' , async ( ) => {
438467 setAngularAppTestingManifest ( [ ] , [ { path : '**' , renderMode : RenderMode . Server , status : 201 } ] ) ;
439468
0 commit comments