(div2 = el)} />
(p = el)}>
(image3 = el)}
xlinkHref="http://i.imgur.com/w7GCRPb.png"
/>
(div3 = el)} />
,
node,
);
[svg, svg2, svg3, svg4].forEach(el => {
expect(el.namespaceURI).toBe('http://www.w3.org/2000/svg');
// SVG tagName is case sensitive.
expect(el.tagName).toBe('svg');
});
expect(g.namespaceURI).toBe('http://www.w3.org/2000/svg');
expect(g.tagName).toBe('g');
expect(g.getAttribute('stroke-width')).toBe('5');
expect(p.namespaceURI).toBe('http://www.w3.org/1999/xhtml');
// DOM tagName is capitalized by browsers.
expect(p.tagName).toBe('P');
[image, image2, image3].forEach(el => {
expect(el.namespaceURI).toBe('http://www.w3.org/2000/svg');
expect(el.tagName).toBe('image');
expect(el.getAttributeNS('http://www.w3.org/1999/xlink', 'href')).toBe(
'http://i.imgur.com/w7GCRPb.png',
);
});
[foreignObject, foreignObject2].forEach(el => {
expect(el.namespaceURI).toBe('http://www.w3.org/2000/svg');
expect(el.tagName).toBe('foreignObject');
});
[div, div2, div3].forEach(el => {
expect(el.namespaceURI).toBe('http://www.w3.org/1999/xhtml');
expect(el.tagName).toBe('DIV');
});
});
it('creates elements with SVG namespace inside SVG tag during update', () => {
let inst,
div,
div2,
foreignObject,
foreignObject2,
g,
image,
image2,
svg,
svg2,
svg3,
svg4;
class App extends React.Component {
state = {step: 0};
render() {
inst = this;
const {step} = this.state;
if (step === 0) {
return null;
}
return (
(g = el)} strokeWidth="5">
(svg2 = el)}>
(foreignObject = el)}>
(svg3 = el)}>
(svg4 = el)} />
(image = el)}
xlinkHref="http://i.imgur.com/w7GCRPb.png"
/>
(div = el)} />
(image2 = el)}
xlinkHref="http://i.imgur.com/w7GCRPb.png"
/>
(foreignObject2 = el)}>
(div2 = el)} />
);
}
}
const node = document.createElement('div');
ReactDOM.render(
(svg = el)}>
,
node,
);
inst.setState({step: 1});
[svg, svg2, svg3, svg4].forEach(el => {
expect(el.namespaceURI).toBe('http://www.w3.org/2000/svg');
// SVG tagName is case sensitive.
expect(el.tagName).toBe('svg');
});
expect(g.namespaceURI).toBe('http://www.w3.org/2000/svg');
expect(g.tagName).toBe('g');
expect(g.getAttribute('stroke-width')).toBe('5');
[image, image2].forEach(el => {
expect(el.namespaceURI).toBe('http://www.w3.org/2000/svg');
expect(el.tagName).toBe('image');
expect(el.getAttributeNS('http://www.w3.org/1999/xlink', 'href')).toBe(
'http://i.imgur.com/w7GCRPb.png',
);
});
[foreignObject, foreignObject2].forEach(el => {
expect(el.namespaceURI).toBe('http://www.w3.org/2000/svg');
expect(el.tagName).toBe('foreignObject');
});
[div, div2].forEach(el => {
expect(el.namespaceURI).toBe('http://www.w3.org/1999/xhtml');
// DOM tagName is capitalized by browsers.
expect(el.tagName).toBe('DIV');
});
});
it('can render SVG into a non-React SVG tree', () => {
const outerSVGRoot = document.createElementNS(
'http://www.w3.org/2000/svg',
'svg',
);
const container = document.createElementNS(
'http://www.w3.org/2000/svg',
'g',
);
outerSVGRoot.appendChild(container);
let image;
ReactDOM.render(
(image = el)} />, container);
expect(image.namespaceURI).toBe('http://www.w3.org/2000/svg');
expect(image.tagName).toBe('image');
});
it('can render HTML into a foreignObject in non-React SVG tree', () => {
const outerSVGRoot = document.createElementNS(
'http://www.w3.org/2000/svg',
'svg',
);
const container = document.createElementNS(
'http://www.w3.org/2000/svg',
'foreignObject',
);
outerSVGRoot.appendChild(container);
let div;
ReactDOM.render( (div = el)} />, container);
expect(div.namespaceURI).toBe('http://www.w3.org/1999/xhtml');
expect(div.tagName).toBe('DIV');
});
});