Skip to content

Commit 27ef842

Browse files
authored
fix(material/icon/testing): Adds size specs to fake icon (#18306)
Adds size specs to the fake icon to match specs of the real implementation. Without this, the rendered blank icon has the default size of an SVG element which is 300x150px which can break layouts.
1 parent bb08fa7 commit 27ef842

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/material/icon/testing/fake-icon-registry.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ export class FakeMatIconRegistry implements PublicApi<MatIconRegistry>, OnDestro
8383
private _generateEmptySvg(): SVGElement {
8484
const emptySvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
8585
emptySvg.classList.add('fake-testing-svg');
86+
// Emulate real icon characteristics from `MatIconRegistry` so size remains consistent in tests.
87+
emptySvg.setAttribute('fit', '');
88+
emptySvg.setAttribute('height', '100%');
89+
emptySvg.setAttribute('width', '100%');
90+
emptySvg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
91+
emptySvg.setAttribute('focusable', 'false');
8692
return emptySvg;
8793
}
8894
}

0 commit comments

Comments
 (0)