2016-06-16 17:36:51 -04:00
|
|
|
import {validateConfig} from '../src/config';
|
|
|
|
|
|
|
|
describe('config', () => {
|
2016-06-21 14:49:42 -04:00
|
|
|
describe('validateConfig', () => {
|
|
|
|
it('should not throw when no errors', () => {
|
2016-06-27 23:10:36 -04:00
|
|
|
validateConfig([{path: 'a', redirectTo: 'b'}, {path: 'b', component: ComponentA}]);
|
2016-06-16 17:36:51 -04:00
|
|
|
});
|
|
|
|
|
2016-07-14 11:28:31 -04: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 14:49:42 -04:00
|
|
|
it('should throw when redirectTo and children are used together', () => {
|
2016-06-16 17:36:51 -04:00
|
|
|
expect(() => {
|
2016-06-21 14:49:42 -04: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 17:36:51 -04:00
|
|
|
});
|
|
|
|
|
2016-07-06 19:19:52 -04:00
|
|
|
it('should throw when redirectTo and loadChildren are used together', () => {
|
|
|
|
expect(() => { validateConfig([{path: 'a', redirectTo: 'b', loadChildren: 'value'}]); })
|
2016-07-06 14:02:16 -04:00
|
|
|
.toThrowError(
|
2016-07-06 19:19:52 -04:00
|
|
|
`Invalid configuration of route 'a': redirectTo and loadChildren cannot be used together`);
|
2016-07-06 14:02:16 -04:00
|
|
|
});
|
|
|
|
|
2016-07-06 19:19:52 -04:00
|
|
|
it('should throw when children and loadChildren are used together', () => {
|
|
|
|
expect(() => { validateConfig([{path: 'a', children: [], loadChildren: 'value'}]); })
|
2016-07-06 14:02:16 -04:00
|
|
|
.toThrowError(
|
2016-07-06 19:19:52 -04:00
|
|
|
`Invalid configuration of route 'a': children and loadChildren cannot be used together`);
|
2016-07-06 14:02:16 -04:00
|
|
|
});
|
|
|
|
|
2016-06-21 14:49:42 -04: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 17:36:51 -04:00
|
|
|
});
|
|
|
|
|
2016-06-21 14:49:42 -04:00
|
|
|
it('should throw when path is missing', () => {
|
2016-06-16 17:36:51 -04:00
|
|
|
expect(() => {
|
2016-06-21 14:49:42 -04:00
|
|
|
validateConfig([{component: '', redirectTo: 'b'}]);
|
2016-06-16 17:36:51 -04:00
|
|
|
}).toThrowError(`Invalid route configuration: routes must have path specified`);
|
|
|
|
});
|
|
|
|
|
2016-06-21 14:49:42 -04:00
|
|
|
it('should throw when none of component and children or direct are missing', () => {
|
|
|
|
expect(() => { validateConfig([{path: 'a'}]); })
|
|
|
|
.toThrowError(
|
2016-07-06 19:19:52 -04:00
|
|
|
`Invalid configuration of route 'a': component, redirectTo, children, loadChildren must be provided`);
|
2016-06-19 17:44:20 -04:00
|
|
|
});
|
|
|
|
|
2016-06-21 14:49:42 -04:00
|
|
|
it('should throw when path starts with a slash', () => {
|
2016-06-16 17:36:51 -04:00
|
|
|
expect(() => {
|
2016-06-27 23:10:36 -04:00
|
|
|
validateConfig([<any>{path: '/a', redirectTo: 'b'}]);
|
2016-06-16 17:36:51 -04:00
|
|
|
}).toThrowError(`Invalid route configuration of route '/a': path cannot start with a slash`);
|
|
|
|
});
|
2016-06-27 23:10:36 -04: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-06-16 17:36:51 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-06-21 14:49:42 -04:00
|
|
|
class ComponentA {}
|
|
|
|
class ComponentB {}
|
|
|
|
class ComponentC {}
|