@@ -4,14 +4,15 @@ import {Component, OnInit, QueryList, ViewChild, ViewChildren} from '@angular/co
4
4
import { async , ComponentFixture , fakeAsync , TestBed , tick } from '@angular/core/testing' ;
5
5
import { By } from '@angular/platform-browser' ;
6
6
import { BrowserAnimationsModule , NoopAnimationsModule } from '@angular/platform-browser/animations' ;
7
+ import { CommonModule } from '@angular/common' ;
7
8
import { Observable } from 'rxjs' ;
8
9
import { MatTab , MatTabGroup , MatTabHeaderPosition , MatTabsModule } from './index' ;
9
10
10
11
11
12
describe ( 'MatTabGroup' , ( ) => {
12
13
beforeEach ( fakeAsync ( ( ) => {
13
14
TestBed . configureTestingModule ( {
14
- imports : [ MatTabsModule , NoopAnimationsModule ] ,
15
+ imports : [ MatTabsModule , CommonModule , NoopAnimationsModule ] ,
15
16
declarations : [
16
17
SimpleTabsTestApp ,
17
18
SimpleDynamicTabsTestApp ,
@@ -21,6 +22,7 @@ describe('MatTabGroup', () => {
21
22
TabGroupWithSimpleApi ,
22
23
TemplateTabs ,
23
24
TabGroupWithAriaInputs ,
25
+ TabGroupWithIsActiveBinding ,
24
26
] ,
25
27
} ) ;
26
28
@@ -195,8 +197,9 @@ describe('MatTabGroup', () => {
195
197
. toBe ( 0 , 'Expected no ripple to show up on label mousedown.' ) ;
196
198
} ) ;
197
199
198
- it ( 'should set the isActive flag on each of the tabs' , ( ) => {
200
+ it ( 'should set the isActive flag on each of the tabs' , fakeAsync ( ( ) => {
199
201
fixture . detectChanges ( ) ;
202
+ tick ( ) ;
200
203
201
204
const tabs = fixture . componentInstance . tabs . toArray ( ) ;
202
205
@@ -206,11 +209,12 @@ describe('MatTabGroup', () => {
206
209
207
210
fixture . componentInstance . selectedIndex = 2 ;
208
211
fixture . detectChanges ( ) ;
212
+ tick ( ) ;
209
213
210
214
expect ( tabs [ 0 ] . isActive ) . toBe ( false ) ;
211
215
expect ( tabs [ 1 ] . isActive ) . toBe ( false ) ;
212
216
expect ( tabs [ 2 ] . isActive ) . toBe ( true ) ;
213
- } ) ;
217
+ } ) ) ;
214
218
215
219
it ( 'should fire animation done event' , fakeAsync ( ( ) => {
216
220
fixture . detectChanges ( ) ;
@@ -567,7 +571,21 @@ describe('MatTabGroup', () => {
567
571
const child = fixture . debugElement . query ( By . css ( '.child' ) ) ;
568
572
expect ( child . nativeElement ) . toBeDefined ( ) ;
569
573
} ) ) ;
570
- } ) ;
574
+ } ) ;
575
+
576
+ describe ( 'special cases' , ( ) => {
577
+ it ( 'should not throw an error when binding isActive to the view' , fakeAsync ( ( ) => {
578
+ const fixture = TestBed . createComponent ( TabGroupWithIsActiveBinding ) ;
579
+
580
+ expect ( ( ) => {
581
+ fixture . detectChanges ( ) ;
582
+ tick ( ) ;
583
+ fixture . detectChanges ( ) ;
584
+ } ) . not . toThrow ( ) ;
585
+
586
+ expect ( fixture . nativeElement . textContent ) . toContain ( 'pizza is active' ) ;
587
+ } ) ) ;
588
+ } ) ;
571
589
572
590
/**
573
591
* Checks that the `selectedIndex` has been updated; checks that the label and body have their
@@ -828,3 +846,17 @@ class TabGroupWithAriaInputs {
828
846
ariaLabel : string ;
829
847
ariaLabelledby : string ;
830
848
}
849
+
850
+
851
+ @Component ( {
852
+ template : `
853
+ <mat-tab-group>
854
+ <mat-tab label="Junk food" #pizza> Pizza, fries </mat-tab>
855
+ <mat-tab label="Vegetables"> Broccoli, spinach </mat-tab>
856
+ </mat-tab-group>
857
+
858
+ <div *ngIf="pizza.isActive">pizza is active</div>
859
+ `
860
+ } )
861
+ class TabGroupWithIsActiveBinding {
862
+ }
0 commit comments