11import { async , TestBed , fakeAsync , tick , ComponentFixture } from '@angular/core/testing' ;
22import { By } from '@angular/platform-browser' ;
33import { IgxGridModule } from './index' ;
4- import { ReorderedColumnsComponent , PagingAndEditingComponent , GridIDNameJobTitleComponent } from '../../test-utils/grid-samples.spec' ;
4+ import {
5+ ReorderedColumnsComponent ,
6+ PagingAndEditingComponent ,
7+ GridIDNameJobTitleComponent ,
8+ GridWithUndefinedDataComponent
9+ } from '../../test-utils/grid-samples.spec' ;
510import { PagingComponent } from '../../test-utils/grid-base-components.spec' ;
611import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
712import { IgxGridComponent } from './grid.component' ;
@@ -21,7 +26,8 @@ describe('IgxGrid - Grid Paging', () => {
2126 ReorderedColumnsComponent ,
2227 PagingComponent ,
2328 PagingAndEditingComponent ,
24- GridIDNameJobTitleComponent
29+ GridIDNameJobTitleComponent ,
30+ GridWithUndefinedDataComponent
2531 ] ,
2632 imports : [ IgxGridModule , NoopAnimationsModule ]
2733 } ) . compileComponents ( ) ;
@@ -63,7 +69,7 @@ describe('IgxGrid - Grid Paging', () => {
6369 verifyGridPager ( fix , 3 , '1' , '1 of 4' , [ true , true , false , false ] ) ;
6470 } ) ) ;
6571
66- it ( 'should paginate data API' , fakeAsync ( ( ) => {
72+ it ( 'should paginate data API' , fakeAsync ( ( ) => {
6773 const fix = TestBed . createComponent ( PagingComponent ) ;
6874 fix . detectChanges ( ) ;
6975
@@ -281,7 +287,7 @@ describe('IgxGrid - Grid Paging', () => {
281287 verifyGridPager ( fix , 2 , '9' , '3 of 3' , [ ] ) ;
282288 } ) ;
283289
284- it ( 'activate/deactivate paging' , fakeAsync ( ( ) => {
290+ it ( 'activate/deactivate paging' , fakeAsync ( ( ) => {
285291 const fix = TestBed . createComponent ( ReorderedColumnsComponent ) ;
286292 const grid = fix . componentInstance . grid ;
287293 fix . detectChanges ( ) ;
@@ -461,6 +467,27 @@ describe('IgxGrid - Grid Paging', () => {
461467 expect ( gridElement . querySelector ( PAGER_CLASS ) ) . not . toBeNull ( ) ;
462468 } ) ) ;
463469
470+ it ( 'should not throw error when data is undefined' , fakeAsync ( ( ) => {
471+ let errorMessage = '' ;
472+ const fix = TestBed . createComponent ( GridWithUndefinedDataComponent ) ;
473+ try {
474+ fix . detectChanges ( ) ;
475+ } catch ( ex ) {
476+ errorMessage = ex . message ;
477+ }
478+ expect ( errorMessage ) . toBe ( '' ) ;
479+ const grid = fix . componentInstance . grid ;
480+ let paginator = grid . nativeElement . querySelector ( PAGER_CLASS ) ;
481+ expect ( paginator ) . toBeNull ( ) ;
482+ expect ( grid . rowList . length ) . toBe ( 0 ) ;
483+ tick ( 305 ) ;
484+ fix . detectChanges ( ) ;
485+
486+ paginator = grid . nativeElement . querySelector ( PAGER_CLASS ) ;
487+ expect ( paginator ) . toBeDefined ( ) ;
488+ expect ( grid . rowList . length ) . toBe ( 5 ) ;
489+ } ) ) ;
490+
464491 function verifyGridPager ( fix , rowsCount , firstCellValue , pagerText , buttonsVisibility ) {
465492 const disabled = 'igx-button--disabled' ;
466493 const grid = fix . componentInstance . grid ;
0 commit comments