@@ -14,11 +14,13 @@ import {Observable} from 'rxjs/Observable';
1414import { combineLatest } from 'rxjs/observable/combineLatest' ;
1515import { map } from 'rxjs/operators/map' ;
1616
17+ import { BaseTreeControl } from './control/base-tree-control' ;
1718import { TreeControl } from './control/tree-control' ;
1819import { FlatTreeControl } from './control/flat-tree-control' ;
1920import { NestedTreeControl } from './control/nested-tree-control' ;
2021import { CdkTreeModule } from './index' ;
2122import { CdkTree } from './tree' ;
23+ import { getTreeControlFunctionsMissingError } from './tree-errors' ;
2224
2325
2426describe ( 'CdkTree' , ( ) => {
@@ -587,6 +589,18 @@ describe('CdkTree', () => {
587589 [ `[topping_3] - [cheese_3] + [base_3]` ] ) ;
588590 } ) ;
589591 } ) ;
592+
593+ it ( 'should throw an error when missing function in nested tree' , ( ) => {
594+ configureCdkTreeTestingModule ( [ NestedCdkErrorTreeApp ] ) ;
595+ expect ( ( ) => TestBed . createComponent ( NestedCdkErrorTreeApp ) . detectChanges ( ) )
596+ . toThrowError ( getTreeControlFunctionsMissingError ( ) . message ) ;
597+ } ) ;
598+
599+ it ( 'should throw an error when missing function in flat tree' , ( ) => {
600+ configureCdkTreeTestingModule ( [ FlatCdkErrorTreeApp ] ) ;
601+ expect ( ( ) => TestBed . createComponent ( FlatCdkErrorTreeApp ) . detectChanges ( ) )
602+ . toThrowError ( getTreeControlFunctionsMissingError ( ) . message ) ;
603+ } ) ;
590604 } ) ;
591605} ) ;
592606
@@ -994,3 +1008,56 @@ class ObservableDataSourceNestedCdkTreeApp {
9941008 @ViewChild ( CdkTree ) tree : CdkTree < TestData > ;
9951009}
9961010
1011+ @Component ( {
1012+ template : `
1013+ <cdk-tree [dataSource]="dataSource" [treeControl]="treeControl">
1014+ <cdk-nested-tree-node *cdkTreeNodeDef="let node" class="customNodeClass">
1015+ {{node.pizzaTopping}} - {{node.pizzaCheese}} + {{node.pizzaBase}}
1016+ <ng-template cdkTreeNodeOutlet></ng-template>
1017+ </cdk-nested-tree-node>
1018+ </cdk-tree>
1019+ `
1020+ } )
1021+ class NestedCdkErrorTreeApp {
1022+ getLevel = ( node : TestData ) => node . level ;
1023+
1024+ isExpandable = ( node : TestData ) => node . children . length > 0 ;
1025+
1026+ treeControl : TreeControl < TestData > = new FlatTreeControl ( this . getLevel , this . isExpandable ) ;
1027+
1028+ dataSource : FakeDataSource | null = new FakeDataSource ( this . treeControl ) ;
1029+
1030+ @ViewChild ( CdkTree ) tree : CdkTree < TestData > ;
1031+ }
1032+
1033+ class FakeTreeControl extends BaseTreeControl < TestData > {
1034+ getDescendants ( _ : TestData ) : TestData [ ] {
1035+ return this . dataNodes ;
1036+ }
1037+
1038+ expandAll ( ) : void {
1039+ // No op
1040+ }
1041+ }
1042+ @Component ( {
1043+ template : `
1044+ <cdk-tree [dataSource]="dataSource" [treeControl]="treeControl">
1045+ <cdk-tree-node *cdkTreeNodeDef="let node" class="customNodeClass">
1046+ {{node.pizzaTopping}} - {{node.pizzaCheese}} + {{node.pizzaBase}}
1047+ <ng-template cdkTreeNodeOutlet></ng-template>
1048+ </cdk-tree-node>
1049+ </cdk-tree>
1050+ `
1051+ } )
1052+ class FlatCdkErrorTreeApp {
1053+
1054+ getLevel = ( node : TestData ) => node . level ;
1055+
1056+ isExpandable = ( node : TestData ) => node . children . length > 0 ;
1057+
1058+ treeControl : TreeControl < TestData > = new FakeTreeControl ( ) ;
1059+
1060+ dataSource : FakeDataSource | null = new FakeDataSource ( this . treeControl ) ;
1061+
1062+ @ViewChild ( CdkTree ) tree : CdkTree < TestData > ;
1063+ }
0 commit comments