|
7 | 7 | Input,
|
8 | 8 | QueryList,
|
9 | 9 | Type,
|
10 |
| - ViewChild |
| 10 | + ViewChild, |
| 11 | + AfterViewInit |
11 | 12 | } from '@angular/core';
|
12 | 13 | import {ComponentFixture, fakeAsync, flush, TestBed} from '@angular/core/testing';
|
13 | 14 | import {BehaviorSubject, combineLatest, Observable, of as observableOf} from 'rxjs';
|
@@ -538,6 +539,17 @@ describe('CdkTable', () => {
|
538 | 539 | .toThrowError(getTableUnknownColumnError('column_a').message);
|
539 | 540 | });
|
540 | 541 |
|
| 542 | + it('should throw an error if a column definition is requested but not defined after render', |
| 543 | + fakeAsync(() => { |
| 544 | + const columnDefinitionMissingAfterRenderFixture = |
| 545 | + createComponent(MissingColumnDefAfterRenderCdkTableApp); |
| 546 | + expect(() => { |
| 547 | + columnDefinitionMissingAfterRenderFixture.detectChanges(); |
| 548 | + flush(); |
| 549 | + columnDefinitionMissingAfterRenderFixture.detectChanges(); |
| 550 | + }).toThrowError(getTableUnknownColumnError('column_a').message); |
| 551 | + })); |
| 552 | + |
541 | 553 | it('should throw an error if the row definitions are missing', () => {
|
542 | 554 | expect(() => createComponent(MissingAllRowDefsCdkTableApp).detectChanges())
|
543 | 555 | .toThrowError(getTableMissingRowDefsError().message);
|
@@ -1974,6 +1986,28 @@ class MissingColumnDefCdkTableApp {
|
1974 | 1986 | dataSource: FakeDataSource = new FakeDataSource();
|
1975 | 1987 | }
|
1976 | 1988 |
|
| 1989 | +@Component({ |
| 1990 | + template: ` |
| 1991 | + <cdk-table [dataSource]="dataSource"> |
| 1992 | + <ng-container cdkColumnDef="column_b"> |
| 1993 | + <cdk-header-cell *cdkHeaderCellDef> Column A</cdk-header-cell> |
| 1994 | + <cdk-cell *cdkCellDef="let row"> {{row.a}}</cdk-cell> |
| 1995 | + </ng-container> |
| 1996 | +
|
| 1997 | + <cdk-header-row *cdkHeaderRowDef="displayedColumns"></cdk-header-row> |
| 1998 | + <cdk-row *cdkRowDef="let row; columns: displayedColumns"></cdk-row> |
| 1999 | + </cdk-table> |
| 2000 | + ` |
| 2001 | +}) |
| 2002 | +class MissingColumnDefAfterRenderCdkTableApp implements AfterViewInit { |
| 2003 | + dataSource: FakeDataSource|null = null; |
| 2004 | + displayedColumns: string[] = []; |
| 2005 | + |
| 2006 | + ngAfterViewInit() { |
| 2007 | + setTimeout(() => { this.displayedColumns = ['column_a']; }, 0); |
| 2008 | + } |
| 2009 | +} |
| 2010 | + |
1977 | 2011 | @Component({
|
1978 | 2012 | template: `
|
1979 | 2013 | <cdk-table [dataSource]="dataSource">
|
|
0 commit comments