Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit e6b46a0

Browse files
committed
test($compile): relax SVG circle verification for "unsized" parents
This currently only seems to be the case on MS Edge (tested on version 25.10586.0.0, Win 10).
1 parent 4d04f4f commit e6b46a0

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

test/ng/compileSpec.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,26 @@ describe('$compile', function() {
231231

232232
describe('svg namespace transcludes', function() {
233233
// this method assumes some sort of sized SVG element is being inspected.
234-
function assertIsValidSvgCircle(elem) {
234+
function assertIsValidSvgCircle(elem, possiblyUnsizedParent) {
235235
expect(isUnknownElement(elem)).toBe(false);
236236
expect(isSVGElement(elem)).toBe(true);
237+
237238
var box = elem.getBoundingClientRect();
238-
expect(box.width === 0 && box.height === 0).toBe(false);
239+
var hasWidthOrHeight = (box.width !== 0) || (box.height !== 0);
240+
241+
if (possiblyUnsizedParent && !hasWidthOrHeight) {
242+
// On MS Edge, assuming `<svg><foreignObject><svg><circle /></svg></foreignObject></svg>`,
243+
// the nested `svg` and `circle` both have 0 width/height, despite having the appropriate
244+
// attributes set.
245+
// In that case, even if the `$compiler` has done its job well, the bounding `ClientRect` is
246+
// not a reliable way to verify a valid SVG circle.
247+
var parent = elem.parentNode;
248+
var parentBox = parent && parent.getBoundingClientRect();
249+
250+
hasWidthOrHeight = parentBox && (parentBox.width === 0) && (parentBox.height === 0);
251+
}
252+
253+
expect(hasWidthOrHeight).toBe(true);
239254
}
240255

241256
it('should handle transcluded svg elements', inject(function($compile) {
@@ -309,7 +324,7 @@ describe('$compile', function() {
309324
document.body.appendChild(element[0]);
310325

311326
var circle = element.find('circle');
312-
assertIsValidSvgCircle(circle[0]);
327+
assertIsValidSvgCircle(circle[0], true);
313328
}));
314329
}
315330

0 commit comments

Comments
 (0)