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