Skip to content

Commit cb36047

Browse files
committed
Add a test for SVG updates
This tests the "jump" reuse code path in particular.
1 parent fb88609 commit cb36047

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

scripts/fiber/tests-passing.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,8 @@ src/renderers/dom/shared/__tests__/ReactDOMInvalidARIAHook-test.js
635635

636636
src/renderers/dom/shared/__tests__/ReactDOMSVG-test.js
637637
* creates initial namespaced markup
638-
* creates elements with svg namespace inside svg tag
638+
* creates elements with SVG namespace inside SVG tag during mount
639+
* creates elements with SVG namespace inside SVG tag during update
639640

640641
src/renderers/dom/shared/__tests__/ReactDOMTextComponent-test.js
641642
* updates a mounted text component in place

src/renderers/dom/shared/__tests__/ReactDOMSVG-test.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('ReactDOMSVG', () => {
3232
expect(markup).toContain('xlink:href="http://i.imgur.com/w7GCRPb.png"');
3333
});
3434

35-
it('creates elements with svg namespace inside svg tag', () => {
35+
it('creates elements with SVG namespace inside SVG tag during mount', () => {
3636
var node = document.createElement('div');
3737
var div, foreignDiv, g, image, image2, p;
3838
ReactDOM.render(
@@ -77,4 +77,47 @@ describe('ReactDOMSVG', () => {
7777
expect(foreignDiv.tagName).toBe('DIV');
7878
});
7979

80+
it('creates elements with SVG namespace inside SVG tag during update', () => {
81+
var inst, foreignDiv, g, image;
82+
83+
class App extends React.Component {
84+
state = {step: 0};
85+
render() {
86+
inst = this;
87+
const {step} = this.state;
88+
if (step === 0) {
89+
return null;
90+
}
91+
return (
92+
<g ref={el => g = el} strokeWidth="5">
93+
<image ref={el => image = el} xlinkHref="http://i.imgur.com/w7GCRPb.png" />
94+
<foreignObject>
95+
<div ref={el => foreignDiv = el} />
96+
</foreignObject>
97+
</g>
98+
);
99+
}
100+
}
101+
102+
var node = document.createElement('div');
103+
ReactDOM.render(
104+
<svg>
105+
<App />
106+
</svg>,
107+
node
108+
);
109+
inst.setState({step: 1});
110+
111+
expect(g.namespaceURI).toBe('http://www.w3.org/2000/svg');
112+
expect(g.tagName).toBe('g');
113+
expect(g.getAttribute('stroke-width')).toBe('5');
114+
expect(image.namespaceURI).toBe('http://www.w3.org/2000/svg');
115+
expect(image.tagName).toBe('image');
116+
expect(
117+
image.getAttributeNS('http://www.w3.org/1999/xlink', 'href')
118+
).toBe('http://i.imgur.com/w7GCRPb.png');
119+
expect(foreignDiv.namespaceURI).toBe('http://www.w3.org/1999/xhtml');
120+
expect(foreignDiv.tagName).toBe('DIV');
121+
});
122+
80123
});

0 commit comments

Comments
 (0)