11import { inject , async , fakeAsync , tick , TestBed } from '@angular/core/testing' ;
22import { SafeResourceUrl , DomSanitizer , SafeHtml } from '@angular/platform-browser' ;
3- import { HttpClientTestingModule , HttpTestingController } from '@angular/common/http/testing' ;
3+ import {
4+ HttpClientTestingModule ,
5+ HttpTestingController ,
6+ TestRequest ,
7+ } from '@angular/common/http/testing' ;
48import { Component , ErrorHandler } from '@angular/core' ;
59import { MatIconModule , MAT_ICON_LOCATION } from './index' ;
610import { MatIconRegistry , getMatIconNoHttpProviderError } from './icon-registry' ;
@@ -189,9 +193,11 @@ describe('MatIcon', () => {
189193 it ( 'should register icon URLs by name' , fakeAsync ( ( ) => {
190194 iconRegistry . addSvgIcon ( 'fluffy' , trustUrl ( 'cat.svg' ) ) ;
191195 iconRegistry . addSvgIcon ( 'fido' , trustUrl ( 'dog.svg' ) ) ;
196+ iconRegistry . addSvgIcon ( 'felix' , trustUrl ( 'auth-cat.svg' ) , { withCredentials : true } ) ;
192197
193198 const fixture = TestBed . createComponent ( IconFromSvgName ) ;
194199 let svgElement : SVGElement ;
200+ let testRequest : TestRequest ;
195201 const testComponent = fixture . componentInstance ;
196202 const iconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
197203
@@ -215,6 +221,15 @@ describe('MatIcon', () => {
215221 svgElement = verifyAndGetSingleSvgChild ( iconElement ) ;
216222 verifyPathChildElement ( svgElement , 'woof' ) ;
217223
224+ // Change icon to one that needs credentials during fetch.
225+ testComponent . iconName = 'felix' ;
226+ fixture . detectChanges ( ) ;
227+ testRequest = http . expectOne ( 'auth-cat.svg' ) ;
228+ expect ( testRequest . request . withCredentials ) . toBeTrue ( ) ;
229+ testRequest . flush ( FAKE_SVGS . cat ) ;
230+ svgElement = verifyAndGetSingleSvgChild ( iconElement ) ;
231+ verifyPathChildElement ( svgElement , 'meow' ) ;
232+
218233 // Assert that a registered icon can be looked-up by url.
219234 iconRegistry . getSvgIconFromUrl ( trustUrl ( 'cat.svg' ) ) . subscribe ( element => {
220235 verifyPathChildElement ( element , 'meow' ) ;
0 commit comments