From 5a993933554bbded840596d4c81eeb1fb641afc9 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Sun, 7 Aug 2016 20:05:05 -0700 Subject: [PATCH] fix(router): route.parent should work for secondary children --- modules/@angular/router/src/utils/tree.ts | 2 +- modules/@angular/router/test/utils/tree.spec.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/@angular/router/src/utils/tree.ts b/modules/@angular/router/src/utils/tree.ts index ad49901e7a..e325d3c7ae 100644 --- a/modules/@angular/router/src/utils/tree.ts +++ b/modules/@angular/router/src/utils/tree.ts @@ -71,7 +71,7 @@ function findPath(expected: T, c: TreeNode, collected: TreeNode[]): 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 []; diff --git a/modules/@angular/router/test/utils/tree.spec.ts b/modules/@angular/router/test/utils/tree.spec.ts index 311ddccdc5..5534175733 100644 --- a/modules/@angular/router/test/utils/tree.spec.ts +++ b/modules/@angular/router/test/utils/tree.spec.ts @@ -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( + new TreeNode(1, [new TreeNode(2, []), new TreeNode(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(new TreeNode(1, [new TreeNode(2, [])])); expect(t.children(1)).toEqual([2]);