@@ -10,28 +10,31 @@ import {wrappedErrorMessage} from '../core/testing/wrapped-error-message';
10
10
11
11
12
12
/** Returns the CSS classes assigned to an element as a sorted array. */
13
- const sortedClassNames = ( elem : Element ) => elem . className . split ( ' ' ) . sort ( ) ;
13
+ function sortedClassNames ( element : Element ) : string [ ] {
14
+ return element . className . split ( ' ' ) . sort ( ) ;
15
+ }
14
16
15
17
/**
16
18
* Verifies that an element contains a single <svg> child element, and returns that child.
17
19
*/
18
- const verifyAndGetSingleSvgChild = ( element : SVGElement ) : any => {
20
+ function verifyAndGetSingleSvgChild ( element : SVGElement ) : SVGElement {
19
21
expect ( element . childNodes . length ) . toBe ( 1 ) ;
20
- const svgChild = < Element > element . childNodes [ 0 ] ;
22
+ const svgChild = element . childNodes [ 0 ] as SVGElement ;
21
23
expect ( svgChild . tagName . toLowerCase ( ) ) . toBe ( 'svg' ) ;
22
24
return svgChild ;
23
- } ;
25
+ }
24
26
25
27
/**
26
28
* Verifies that an element contains a single <path> child element whose "id" attribute has
27
29
* the specified value.
28
30
*/
29
- const verifyPathChildElement = ( element : Element , attributeValue : string ) => {
31
+ function verifyPathChildElement ( element : Element , attributeValue : string ) : void {
30
32
expect ( element . childNodes . length ) . toBe ( 1 ) ;
31
- const pathElement = < Element > element . childNodes [ 0 ] ;
33
+ const pathElement = element . childNodes [ 0 ] as SVGPathElement ;
32
34
expect ( pathElement . tagName . toLowerCase ( ) ) . toBe ( 'path' ) ;
33
35
expect ( pathElement . getAttribute ( 'id' ) ) . toBe ( attributeValue ) ;
34
- } ;
36
+ }
37
+
35
38
36
39
describe ( 'MdIcon' , ( ) => {
37
40
@@ -240,6 +243,25 @@ describe('MdIcon', () => {
240
243
expect ( httpRequestUrls . sort ( ) ) . toEqual ( [ 'farm-set-1.svg' , 'farm-set-2.svg' ] ) ;
241
244
} ) ;
242
245
246
+ it ( 'should unwrap <symbol> nodes' , ( ) => {
247
+ mdIconRegistry . addSvgIconSetInNamespace ( 'farm' , trust ( 'farm-set-3.svg' ) ) ;
248
+
249
+ const fixture = TestBed . createComponent ( MdIconFromSvgNameTestApp ) ;
250
+ const testComponent = fixture . componentInstance ;
251
+ const mdIconElement = fixture . debugElement . nativeElement . querySelector ( 'md-icon' ) ;
252
+
253
+ testComponent . iconName = 'farm:duck' ;
254
+ fixture . detectChanges ( ) ;
255
+
256
+ const svgElement = verifyAndGetSingleSvgChild ( mdIconElement ) ;
257
+ const firstChild = svgElement . childNodes [ 0 ] ;
258
+
259
+ expect ( svgElement . querySelector ( 'symbol' ) ) . toBeFalsy ( ) ;
260
+ expect ( svgElement . childNodes . length ) . toBe ( 1 ) ;
261
+ expect ( firstChild . nodeName . toLowerCase ( ) ) . toBe ( 'path' ) ;
262
+ expect ( ( firstChild as HTMLElement ) . getAttribute ( 'id' ) ) . toBe ( 'quack' ) ;
263
+ } ) ;
264
+
243
265
it ( 'should not wrap <svg> elements in icon sets in another svg tag' , ( ) => {
244
266
mdIconRegistry . addSvgIconSet ( trust ( 'arrow-set.svg' ) ) ;
245
267
0 commit comments