@@ -10,28 +10,31 @@ import {wrappedErrorMessage} from '../core/testing/wrapped-error-message';
1010
1111
1212/** 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+ }
1416
1517/**
1618 * Verifies that an element contains a single <svg> child element, and returns that child.
1719 */
18- const verifyAndGetSingleSvgChild = ( element : SVGElement ) : any => {
20+ function verifyAndGetSingleSvgChild ( element : SVGElement ) : SVGElement {
1921 expect ( element . childNodes . length ) . toBe ( 1 ) ;
20- const svgChild = < Element > element . childNodes [ 0 ] ;
22+ const svgChild = element . childNodes [ 0 ] as SVGElement ;
2123 expect ( svgChild . tagName . toLowerCase ( ) ) . toBe ( 'svg' ) ;
2224 return svgChild ;
23- } ;
25+ }
2426
2527/**
2628 * Verifies that an element contains a single <path> child element whose "id" attribute has
2729 * the specified value.
2830 */
29- const verifyPathChildElement = ( element : Element , attributeValue : string ) => {
31+ function verifyPathChildElement ( element : Element , attributeValue : string ) : void {
3032 expect ( element . childNodes . length ) . toBe ( 1 ) ;
31- const pathElement = < Element > element . childNodes [ 0 ] ;
33+ const pathElement = element . childNodes [ 0 ] as SVGPathElement ;
3234 expect ( pathElement . tagName . toLowerCase ( ) ) . toBe ( 'path' ) ;
3335 expect ( pathElement . getAttribute ( 'id' ) ) . toBe ( attributeValue ) ;
34- } ;
36+ }
37+
3538
3639describe ( 'MdIcon' , ( ) => {
3740
@@ -240,6 +243,25 @@ describe('MdIcon', () => {
240243 expect ( httpRequestUrls . sort ( ) ) . toEqual ( [ 'farm-set-1.svg' , 'farm-set-2.svg' ] ) ;
241244 } ) ;
242245
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+
243265 it ( 'should not wrap <svg> elements in icon sets in another svg tag' , ( ) => {
244266 mdIconRegistry . addSvgIconSet ( trust ( 'arrow-set.svg' ) ) ;
245267
0 commit comments