|
| 1 | +import {fakeAsync, flush} from '@angular/core/testing'; |
1 | 2 | import {of as observableOf} from 'rxjs';
|
2 | 3 | import {NestedTreeControl} from './nested-tree-control';
|
3 | 4 |
|
@@ -92,6 +93,20 @@ describe('CdkNestedTreeControl', () => {
|
92 | 93 | .toBe(totalNumber, `Expect ${totalNumber} expanded nodes`);
|
93 | 94 | });
|
94 | 95 |
|
| 96 | + // Note that this needs to be `fakeAsync` in order to |
| 97 | + // catch the error inside an observable correctly. |
| 98 | + it('should handle null children', fakeAsync(() => { |
| 99 | + const nodes = generateData(3, 2); |
| 100 | + |
| 101 | + nodes[1].children = null!; |
| 102 | + treeControl.dataNodes = nodes; |
| 103 | + |
| 104 | + expect(() => { |
| 105 | + treeControl.expandAll(); |
| 106 | + flush(); |
| 107 | + }).not.toThrow(); |
| 108 | + })); |
| 109 | + |
95 | 110 | describe('with children array', () => {
|
96 | 111 | let getStaticChildren = (node: TestData) => node.children;
|
97 | 112 |
|
@@ -201,12 +216,12 @@ export class TestData {
|
201 | 216 |
|
202 | 217 | function generateData(dataLength: number, childLength: number, grandChildLength: number = 0)
|
203 | 218 | : TestData[] {
|
204 |
| - let data = <any>[]; |
| 219 | + let data: TestData[] = []; |
205 | 220 | let nextIndex = 0;
|
206 | 221 | for (let i = 0; i < dataLength; i++) {
|
207 |
| - let children = <any>[]; |
| 222 | + let children: TestData[] = []; |
208 | 223 | for (let j = 0; j < childLength; j++) {
|
209 |
| - let grandChildren = <any>[]; |
| 224 | + let grandChildren: TestData[] = []; |
210 | 225 | for (let k = 0; k < grandChildLength; k++) {
|
211 | 226 | grandChildren.push(new TestData(`a_${nextIndex}`, `b_${nextIndex}`, `c_${nextIndex++}`, 3));
|
212 | 227 | }
|
|
0 commit comments