angular-cn/modules/@angular/router/test/config.spec.ts

47 lines
1.7 KiB
TypeScript
Raw Normal View History

import {validateConfig} from '../src/config';
describe('config', () => {
2016-06-21 14:49:42 -04:00
describe('validateConfig', () => {
it('should not throw when no errors', () => {
validateConfig([{path: '', redirectTo: 'b'}, {path: 'b', component: ComponentA}]);
});
2016-06-21 14:49:42 -04:00
it('should throw when redirectTo and children are used together', () => {
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-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-21 14:49:42 -04:00
it('should throw when path is missing', () => {
expect(() => {
2016-06-21 14:49:42 -04:00
validateConfig([{component: '', redirectTo: 'b'}]);
}).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(
`Invalid configuration of route 'a': component, redirectTo, children must be provided`);
});
2016-06-21 14:49:42 -04:00
it('should throw when path starts with a slash', () => {
expect(() => {
2016-06-21 14:49:42 -04:00
validateConfig([<any>{path: '/a', componenta: '', redirectTo: 'b'}]);
}).toThrowError(`Invalid route configuration of route '/a': path cannot start with a slash`);
});
});
});
2016-06-21 14:49:42 -04:00
class ComponentA {}
class ComponentB {}
class ComponentC {}