import { RouterTestingModule } from '@angular/router/testing' ; import { HttpClientModule } from '@angular/common/http' ; import { NO_ERRORS_SCHEMA , SecurityContext } from '@angular/core' ; import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ; import { DataTableDirective , DataTablesModule } from 'angular-datatables' ; import { MarkdownModule } from 'ngx-markdown' ; import { BaseDemoComponent } from '../base-demo/base-demo.component' ; import { AppRoutingModule } from '../app.routing' ; import { FormsModule } from '@angular/forms' ; import { UsingNgPipeComponent } from './using-ng-pipe.component' ; import { UpperCasePipe } from '@angular/common' ; import { By } from '@angular/platform-browser' ; import { Person } from 'app/person' ; let fixture , component = null ; describe ( 'UsingNgPipeComponent' , ( ) => { beforeEach ( ( ) => { fixture = TestBed . configureTestingModule ( { declarations : [ BaseDemoComponent , UsingNgPipeComponent , DataTableDirective ] , imports : [ AppRoutingModule , RouterTestingModule , DataTablesModule . forRoot ( ) , HttpClientModule , MarkdownModule . forRoot ( { sanitize : SecurityContext . NONE } ) , FormsModule ] , schemas : [ NO_ERRORS_SCHEMA ] , providers : [ UpperCasePipe ] } ) . createComponent ( UsingNgPipeComponent ) ; component = fixture . componentInstance ; fixture . detectChanges ( ) ; } ) ; it ( 'should create the app' , waitForAsync ( ( ) => { const app = fixture . debugElement . componentInstance ; expect ( app ) . toBeTruthy ( ) ; } ) ) ; it ( 'should have title "Using Angular Pipe"' , waitForAsync ( ( ) => { const app = fixture . debugElement . componentInstance as UsingNgPipeComponent ; expect ( app . pageTitle ) . toBe ( 'Using Angular Pipe' ) ; } ) ) ; it ( 'should have firstName, lastName columns have text in uppercase' , async ( ) => { const app = fixture . debugElement . componentInstance as UsingNgPipeComponent ; await fixture . whenStable ( ) ; const query = fixture . debugElement . query ( By . directive ( DataTableDirective ) ) ; const dir = query . injector . get ( DataTableDirective ) ; expect ( dir ) . toBeTruthy ( ) ; const instance = await dir . dtInstance ; const rows = fixture . nativeElement . querySelectorAll ( 'tbody tr' ) ; const testsArray = [ 0 , 3 , 6 ] ; const expectedArray = testsArray . map ( _ => true ) ; expect ( testsArray . map ( index => { const dataRow = rows [ index ] ; const firstNameFromData = ( instance . row ( dataRow ) . data ( ) as Person ) . firstName ; const firstNameFromTable = $ ( 'td:nth-child(2)' , dataRow ) . text ( ) ; const lastNameFromData = ( instance . row ( dataRow ) . data ( ) as Person ) . lastName ; const lastNameFromTable = $ ( 'td:nth-child(3)' , dataRow ) . text ( ) ; return firstNameFromTable === firstNameFromData . toUpperCase ( ) && lastNameFromTable === lastNameFromData . toUpperCase ( ) ; } ) ) . toEqual ( expectedArray ) ; } ) ; } ) ;