11import { inject , async , fakeAsync , tick , TestBed } from '@angular/core/testing' ;
22import { SafeResourceUrl , DomSanitizer , SafeHtml } from '@angular/platform-browser' ;
33import { HttpClientTestingModule , HttpTestingController } from '@angular/common/http/testing' ;
4- import { Component } from '@angular/core' ;
4+ import { Component , ErrorHandler } from '@angular/core' ;
55import { MatIconModule , MAT_ICON_LOCATION } from './index' ;
66import { MatIconRegistry , getMatIconNoHttpProviderError } from './icon-registry' ;
77import { FAKE_SVGS } from './fake-svgs' ;
@@ -40,11 +40,13 @@ function verifyPathChildElement(element: Element, attributeValue: string): void
4040
4141describe ( 'MatIcon' , ( ) => {
4242 let fakePath : string ;
43+ let errorHandler : jasmine . SpyObj < ErrorHandler > ;
4344
4445 beforeEach ( async ( ( ) => {
4546 // The $ prefix tells Karma not to try to process the
4647 // request so that we don't get warnings in our logs.
4748 fakePath = '/$fake-path' ;
49+ errorHandler = jasmine . createSpyObj ( 'errorHandler' , [ 'handleError' ] ) ;
4850
4951 TestBed . configureTestingModule ( {
5052 imports : [ HttpClientTestingModule , MatIconModule ] ,
@@ -59,10 +61,16 @@ describe('MatIcon', () => {
5961 SvgIconWithUserContent ,
6062 IconWithLigatureAndSvgBinding ,
6163 ] ,
62- providers : [ {
63- provide : MAT_ICON_LOCATION ,
64- useValue : { getPathname : ( ) => fakePath }
65- } ]
64+ providers : [
65+ {
66+ provide : MAT_ICON_LOCATION ,
67+ useValue : { getPathname : ( ) => fakePath }
68+ } ,
69+ {
70+ provide : ErrorHandler ,
71+ useValue : errorHandler ,
72+ } ,
73+ ]
6674 } ) ;
6775
6876 TestBed . compileComponents ( ) ;
@@ -80,15 +88,15 @@ describe('MatIcon', () => {
8088 } ) ) ;
8189
8290 it ( 'should include notranslate class by default' , ( ) => {
83- let fixture = TestBed . createComponent ( IconWithColor ) ;
91+ const fixture = TestBed . createComponent ( IconWithColor ) ;
8492
8593 const matIconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
8694 expect ( matIconElement . classList . contains ( 'notranslate' ) )
8795 . toBeTruthy ( 'Expected the mat-icon element to include the notranslate class' ) ;
8896 } ) ;
8997
9098 it ( 'should apply class based on color attribute' , ( ) => {
91- let fixture = TestBed . createComponent ( IconWithColor ) ;
99+ const fixture = TestBed . createComponent ( IconWithColor ) ;
92100
93101 const testComponent = fixture . componentInstance ;
94102 const matIconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
@@ -100,7 +108,7 @@ describe('MatIcon', () => {
100108 } ) ;
101109
102110 it ( 'should apply a class if there is no color' , ( ) => {
103- let fixture = TestBed . createComponent ( IconWithColor ) ;
111+ const fixture = TestBed . createComponent ( IconWithColor ) ;
104112
105113 const testComponent = fixture . componentInstance ;
106114 const matIconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
@@ -140,7 +148,7 @@ describe('MatIcon', () => {
140148
141149 describe ( 'Ligature icons' , ( ) => {
142150 it ( 'should add material-icons class by default' , ( ) => {
143- let fixture = TestBed . createComponent ( IconWithLigature ) ;
151+ const fixture = TestBed . createComponent ( IconWithLigature ) ;
144152
145153 const testComponent = fixture . componentInstance ;
146154 const matIconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
@@ -153,7 +161,7 @@ describe('MatIcon', () => {
153161 it ( 'should use alternate icon font if set' , ( ) => {
154162 iconRegistry . setDefaultFontSetClass ( 'myfont' ) ;
155163
156- let fixture = TestBed . createComponent ( IconWithLigature ) ;
164+ const fixture = TestBed . createComponent ( IconWithLigature ) ;
157165
158166 const testComponent = fixture . componentInstance ;
159167 const matIconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
@@ -165,7 +173,7 @@ describe('MatIcon', () => {
165173
166174 it ( 'should not clear the text of a ligature icon if the svgIcon is bound to something falsy' ,
167175 ( ) => {
168- let fixture = TestBed . createComponent ( IconWithLigatureAndSvgBinding ) ;
176+ const fixture = TestBed . createComponent ( IconWithLigatureAndSvgBinding ) ;
169177
170178 const testComponent = fixture . componentInstance ;
171179 const matIconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
@@ -182,7 +190,7 @@ describe('MatIcon', () => {
182190 iconRegistry . addSvgIcon ( 'fluffy' , trustUrl ( 'cat.svg' ) ) ;
183191 iconRegistry . addSvgIcon ( 'fido' , trustUrl ( 'dog.svg' ) ) ;
184192
185- let fixture = TestBed . createComponent ( IconFromSvgName ) ;
193+ const fixture = TestBed . createComponent ( IconFromSvgName ) ;
186194 let svgElement : SVGElement ;
187195 const testComponent = fixture . componentInstance ;
188196 const iconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
@@ -219,7 +227,7 @@ describe('MatIcon', () => {
219227 iconRegistry . addSvgIcon ( 'fluffy' , trustUrl ( 'cat.svg' ) , { viewBox : '0 0 27 27' } ) ;
220228 iconRegistry . addSvgIcon ( 'fido' , trustUrl ( 'dog.svg' ) , { viewBox : '0 0 43 43' } ) ;
221229
222- let fixture = TestBed . createComponent ( IconFromSvgName ) ;
230+ const fixture = TestBed . createComponent ( IconFromSvgName ) ;
223231 let svgElement : SVGElement ;
224232 const testComponent = fixture . componentInstance ;
225233 const iconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
@@ -242,7 +250,7 @@ describe('MatIcon', () => {
242250 iconRegistry . addSvgIcon ( 'fluffy' , 'farm-set-1.svg' ) ;
243251
244252 expect ( ( ) => {
245- let fixture = TestBed . createComponent ( IconFromSvgName ) ;
253+ const fixture = TestBed . createComponent ( IconFromSvgName ) ;
246254 fixture . componentInstance . iconName = 'fluffy' ;
247255 fixture . detectChanges ( ) ;
248256 } ) . toThrowError ( / u n s a f e v a l u e u s e d i n a r e s o u r c e U R L c o n t e x t / ) ;
@@ -252,12 +260,30 @@ describe('MatIcon', () => {
252260 iconRegistry . addSvgIconSetInNamespace ( 'farm' , 'farm-set-1.svg' ) ;
253261
254262 expect ( ( ) => {
255- let fixture = TestBed . createComponent ( IconFromSvgName ) ;
263+ const fixture = TestBed . createComponent ( IconFromSvgName ) ;
256264 fixture . componentInstance . iconName = 'farm:pig' ;
257265 fixture . detectChanges ( ) ;
258266 } ) . toThrowError ( / u n s a f e v a l u e u s e d i n a r e s o u r c e U R L c o n t e x t / ) ;
259267 } ) ;
260268
269+
270+ it ( 'should delegate http error logging to the ErrorHandler' , ( ) => {
271+ iconRegistry . addSvgIconSetInNamespace ( 'farm' , trustUrl ( 'farm-set-1.svg' ) ) ;
272+
273+ const fixture = TestBed . createComponent ( IconFromSvgName ) ;
274+ const testComponent = fixture . componentInstance ;
275+
276+ testComponent . iconName = 'farm:pig' ;
277+ fixture . detectChanges ( ) ;
278+ http . expectOne ( 'farm-set-1.svg' ) . error ( new ErrorEvent ( 'Network error' ) ) ;
279+ fixture . detectChanges ( ) ;
280+
281+ expect ( errorHandler . handleError ) . toHaveBeenCalledTimes ( 1 ) ;
282+ expect ( errorHandler . handleError . calls . argsFor ( 0 ) [ 0 ] . message ) . toEqual (
283+ 'Loading icon set URL: farm-set-1.svg failed: Http failure response ' +
284+ 'for farm-set-1.svg: 0 ' ) ;
285+ } ) ;
286+
261287 it ( 'should extract icon from SVG icon set' , ( ) => {
262288 iconRegistry . addSvgIconSetInNamespace ( 'farm' , trustUrl ( 'farm-set-1.svg' ) ) ;
263289
@@ -491,7 +517,7 @@ describe('MatIcon', () => {
491517 it ( 'should remove the SVG element from the DOM when the binding is cleared' , ( ) => {
492518 iconRegistry . addSvgIconSet ( trustUrl ( 'arrow-set.svg' ) ) ;
493519
494- let fixture = TestBed . createComponent ( IconFromSvgName ) ;
520+ const fixture = TestBed . createComponent ( IconFromSvgName ) ;
495521
496522 const testComponent = fixture . componentInstance ;
497523 const icon = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
@@ -534,7 +560,7 @@ describe('MatIcon', () => {
534560 iconRegistry . addSvgIconLiteral ( 'fluffy' , trustHtml ( FAKE_SVGS . cat ) ) ;
535561 iconRegistry . addSvgIconLiteral ( 'fido' , trustHtml ( FAKE_SVGS . dog ) ) ;
536562
537- let fixture = TestBed . createComponent ( IconFromSvgName ) ;
563+ const fixture = TestBed . createComponent ( IconFromSvgName ) ;
538564 let svgElement : SVGElement ;
539565 const testComponent = fixture . componentInstance ;
540566 const iconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
@@ -561,7 +587,7 @@ describe('MatIcon', () => {
561587 iconRegistry . addSvgIconLiteral ( 'fluffy' , trustHtml ( FAKE_SVGS . cat ) , { viewBox : '0 0 43 43' } ) ;
562588 iconRegistry . addSvgIconLiteral ( 'fido' , trustHtml ( FAKE_SVGS . dog ) , { viewBox : '0 0 27 27' } ) ;
563589
564- let fixture = TestBed . createComponent ( IconFromSvgName ) ;
590+ const fixture = TestBed . createComponent ( IconFromSvgName ) ;
565591 let svgElement : SVGElement ;
566592 const testComponent = fixture . componentInstance ;
567593 const iconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
@@ -916,7 +942,7 @@ describe('MatIcon without HttpClientModule', () => {
916942 expect ( ( ) => {
917943 iconRegistry . addSvgIcon ( 'fido' , sanitizer . bypassSecurityTrustResourceUrl ( 'dog.svg' ) ) ;
918944
919- let fixture = TestBed . createComponent ( IconFromSvgName ) ;
945+ const fixture = TestBed . createComponent ( IconFromSvgName ) ;
920946
921947 fixture . componentInstance . iconName = 'fido' ;
922948 fixture . detectChanges ( ) ;
0 commit comments