@@ -129,6 +129,15 @@ describe('MdTabGroup', () => {
129129 fixture . detectChanges ( ) ;
130130 expect ( component . selectedIndex ) . toBe ( 2 ) ;
131131 } ) ;
132+
133+ it ( 'should not crash when setting the selected index to NaN' , ( ) => {
134+ let component = fixture . debugElement . componentInstance ;
135+
136+ expect ( ( ) => {
137+ component . selectedIndex = NaN ;
138+ fixture . detectChanges ( ) ;
139+ } ) . not . toThrow ( ) ;
140+ } ) ;
132141 } ) ;
133142
134143 describe ( 'dynamic binding tabs' , ( ) => {
@@ -244,19 +253,19 @@ describe('MdTabGroup', () => {
244253 * Checks that the `selectedIndex` has been updated; checks that the label and body have their
245254 * respective `active` classes
246255 */
247- function checkSelectedIndex ( index : number , fixture : ComponentFixture < any > ) {
256+ function checkSelectedIndex ( expectedIndex : number , fixture : ComponentFixture < any > ) {
248257 fixture . detectChanges ( ) ;
249258
250259 let tabComponent : MdTabGroup = fixture . debugElement
251260 . query ( By . css ( 'md-tab-group' ) ) . componentInstance ;
252- expect ( tabComponent . selectedIndex ) . toBe ( index ) ;
261+ expect ( tabComponent . selectedIndex ) . toBe ( expectedIndex ) ;
253262
254263 let tabLabelElement = fixture . debugElement
255- . query ( By . css ( `.md-tab-label:nth-of-type(${ index + 1 } )` ) ) . nativeElement ;
264+ . query ( By . css ( `.md-tab-label:nth-of-type(${ expectedIndex + 1 } )` ) ) . nativeElement ;
256265 expect ( tabLabelElement . classList . contains ( 'md-tab-label-active' ) ) . toBe ( true ) ;
257266
258267 let tabContentElement = fixture . debugElement
259- . query ( By . css ( `md-tab-body:nth-of-type(${ index + 1 } )` ) ) . nativeElement ;
268+ . query ( By . css ( `md-tab-body:nth-of-type(${ expectedIndex + 1 } )` ) ) . nativeElement ;
260269 expect ( tabContentElement . classList . contains ( 'md-tab-body-active' ) ) . toBe ( true ) ;
261270 }
262271
0 commit comments