| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-16 14:36:51 -07:00
										 |  |  | import {validateConfig} from '../src/config'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('config', () => { | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |   describe('validateConfig', () => { | 
					
						
							|  |  |  |     it('should not throw when no errors', () => { | 
					
						
							| 
									
										
										
										
											2016-06-27 20:10:36 -07:00
										 |  |  |       validateConfig([{path: 'a', redirectTo: 'b'}, {path: 'b', component: ComponentA}]); | 
					
						
							| 
									
										
										
										
											2016-06-16 14:36:51 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-15 00:28:31 +09:00
										 |  |  |     it('should throw when Array is passed', () => { | 
					
						
							|  |  |  |       expect(() => { | 
					
						
							|  |  |  |         validateConfig([ | 
					
						
							|  |  |  |           {path: 'a', component: ComponentA}, | 
					
						
							|  |  |  |           [{path: 'b', component: ComponentB}, {path: 'c', component: ComponentC}] | 
					
						
							|  |  |  |         ]); | 
					
						
							|  |  |  |       }).toThrowError(`Invalid route configuration: Array cannot be specified`); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |     it('should throw when redirectTo and children are used together', () => { | 
					
						
							| 
									
										
										
										
											2016-06-16 14:36:51 -07:00
										 |  |  |       expect(() => { | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |         validateConfig( | 
					
						
							|  |  |  |             [{path: 'a', redirectTo: 'b', children: [{path: 'b', component: ComponentA}]}]); | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |           .toThrowError( | 
					
						
							|  |  |  |               `Invalid configuration of route 'a': redirectTo and children cannot be used together`); | 
					
						
							| 
									
										
										
										
											2016-06-16 14:36:51 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-06 16:19:52 -07:00
										 |  |  |     it('should throw when redirectTo and loadChildren are used together', () => { | 
					
						
							|  |  |  |       expect(() => { validateConfig([{path: 'a', redirectTo: 'b', loadChildren: 'value'}]); }) | 
					
						
							| 
									
										
										
										
											2016-07-06 11:02:16 -07:00
										 |  |  |           .toThrowError( | 
					
						
							| 
									
										
										
										
											2016-07-06 16:19:52 -07:00
										 |  |  |               `Invalid configuration of route 'a': redirectTo and loadChildren cannot be used together`); | 
					
						
							| 
									
										
										
										
											2016-07-06 11:02:16 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-06 16:19:52 -07:00
										 |  |  |     it('should throw when children and loadChildren are used together', () => { | 
					
						
							|  |  |  |       expect(() => { validateConfig([{path: 'a', children: [], loadChildren: 'value'}]); }) | 
					
						
							| 
									
										
										
										
											2016-07-06 11:02:16 -07:00
										 |  |  |           .toThrowError( | 
					
						
							| 
									
										
										
										
											2016-07-06 16:19:52 -07:00
										 |  |  |               `Invalid configuration of route 'a': children and loadChildren cannot be used together`); | 
					
						
							| 
									
										
										
										
											2016-07-06 11:02:16 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |     it('should throw when component and redirectTo are used together', () => { | 
					
						
							|  |  |  |       expect(() => { validateConfig([{path: 'a', component: ComponentA, redirectTo: 'b'}]); }) | 
					
						
							|  |  |  |           .toThrowError( | 
					
						
							|  |  |  |               `Invalid configuration of route 'a': redirectTo and component cannot be used together`); | 
					
						
							| 
									
										
										
										
											2016-06-16 14:36:51 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |     it('should throw when path is missing', () => { | 
					
						
							| 
									
										
										
										
											2016-06-16 14:36:51 -07:00
										 |  |  |       expect(() => { | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |         validateConfig([{component: '', redirectTo: 'b'}]); | 
					
						
							| 
									
										
										
										
											2016-06-16 14:36:51 -07:00
										 |  |  |       }).toThrowError(`Invalid route configuration: routes must have path specified`); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |     it('should throw when none of component and children or direct are missing', () => { | 
					
						
							|  |  |  |       expect(() => { validateConfig([{path: 'a'}]); }) | 
					
						
							|  |  |  |           .toThrowError( | 
					
						
							| 
									
										
										
										
											2016-07-20 14:47:51 -07:00
										 |  |  |               `Invalid configuration of route 'a': one of the following must be provided (component or redirectTo or children or loadChildren)`); | 
					
						
							| 
									
										
										
										
											2016-06-19 14:44:20 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  |     it('should throw when path starts with a slash', () => { | 
					
						
							| 
									
										
										
										
											2016-06-16 14:36:51 -07:00
										 |  |  |       expect(() => { | 
					
						
							| 
									
										
										
										
											2016-06-27 20:10:36 -07:00
										 |  |  |         validateConfig([<any>{path: '/a', redirectTo: 'b'}]); | 
					
						
							| 
									
										
										
										
											2016-06-16 14:36:51 -07:00
										 |  |  |       }).toThrowError(`Invalid route configuration of route '/a': path cannot start with a slash`); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-06-27 20:10:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should throw when emptyPath is used with redirectTo without explicitly providing matching', | 
					
						
							|  |  |  |        () => { | 
					
						
							|  |  |  |          expect(() => { | 
					
						
							|  |  |  |            validateConfig([<any>{path: '', redirectTo: 'b'}]); | 
					
						
							|  |  |  |          }).toThrowError(/Invalid route configuration of route '{path: "", redirectTo: "b"}'/); | 
					
						
							|  |  |  |        }); | 
					
						
							| 
									
										
										
										
											2016-07-29 09:59:50 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should throw when pathPatch is invalid', () => { | 
					
						
							|  |  |  |       expect(() => { validateConfig([{path: 'a', pathMatch: 'invalid', component: 'b'}]); }) | 
					
						
							|  |  |  |           .toThrowError( | 
					
						
							|  |  |  |               /Invalid configuration of route 'a': pathMatch can only be set to 'prefix' or 'full'/); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-06-16 14:36:51 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 11:49:42 -07:00
										 |  |  | class ComponentA {} | 
					
						
							|  |  |  | class ComponentB {} | 
					
						
							|  |  |  | class ComponentC {} |