feat(router): add route config validation

This commit is contained in:
vsavkin
2016-06-16 14:36:51 -07:00
parent 7e12208ca6
commit ca23b4c55f
4 changed files with 80 additions and 3 deletions

View File

@ -0,0 +1,50 @@
import {validateConfig} from '../src/config';
describe('config', () => {
describe("validateConfig", () => {
it("should not throw when no errors", () => {
validateConfig([
{ path: '', redirectTo: 'b' },
{ path: 'b', component: ComponentA }
]);
});
it("should throw when redirectTo and children are used together", () => {
expect(() => {
validateConfig([
{ path: 'a', redirectTo: 'b', children: [
{path: 'b', component: ComponentA}
] }
]);
}).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([
{ path: 'a', component: ComponentA, redirectTo: 'b' }
]);
}).toThrowError(`Invalid configuration of route 'a': redirectTo and component cannot be used together`);
});
it("should throw when path is missing", () => {
expect(() => {
validateConfig([
{ component: '', redirectTo: 'b' }
]);
}).toThrowError(`Invalid route configuration: routes must have path specified`);
});
it("should throw when path starts with a slash", () => {
expect(() => {
validateConfig([
{ path: '/a', componenta: '', redirectTo: 'b' }
]);
}).toThrowError(`Invalid route configuration of route '/a': path cannot start with a slash`);
});
});
});
class ComponentA {}
class ComponentB {}
class ComponentC {}