fix(router): route.parent should work for secondary children

This commit is contained in:
vsavkin 2016-08-07 20:05:05 -07:00 committed by Alex Rickabaugh
parent afcb3c0035
commit 5a99393355
2 changed files with 8 additions and 1 deletions

View File

@ -71,7 +71,7 @@ function findPath<T>(expected: T, c: TreeNode<T>, collected: TreeNode<T>[]): Tre
for (let cc of c.children) {
const cloned = collected.slice(0);
const r = findPath(expected, cc, cloned);
if (r) return r;
if (r.length > 0) return r;
}
return [];

View File

@ -20,6 +20,13 @@ describe('tree', () => {
expect(t.parent(2)).toEqual(1);
});
it('should return the parent of a node (second child)', () => {
const t = new Tree<any>(
new TreeNode<number>(1, [new TreeNode<number>(2, []), new TreeNode<number>(3, [])]));
expect(t.parent(1)).toEqual(null);
expect(t.parent(3)).toEqual(1);
});
it('should return the children of a node', () => {
const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])]));
expect(t.children(1)).toEqual([2]);