@samitouri / QOS-React-2 / commits / ba418c6014

Test that text spans aren't remounted needlessly

While working on #2382, I accidentally broke this behavior (causing text components to get unmounted and remounted for any update) but we didn't have any unit test for it. Now we do. Test Plan: jest TextComponent

Ben Alpert committed Nov 6, 2014 at 23:19 UTC ba418c6014a3c812b2efb97f40f0a65609394181
1 file changed +18 -2
src/core/__tests__/ReactTextComponent-test.js
+18 -2
@@ -18,12 +18,28 @@ describe('ReactTextComponent', function() {
18 React = require('React');
19 });
20
21 - it('should escape the rootID', function(){
21 + it('should escape the rootID', function() {
22 var ThisThingShouldBeEscaped = '">>> LULZ <<<"';
23 var ThisThingWasBeEscaped = '&quot;&gt;&gt;&gt; LULZ &lt;&lt;&lt;&quot;';
24 var thing = <div><span key={ThisThingShouldBeEscaped}>LULZ</span></div>;
25 var html = React.renderToString(thing);
26 expect(html).not.toContain(ThisThingShouldBeEscaped);
27 expect(html).toContain(ThisThingWasBeEscaped);
28 - })
28 + });
29 +
30 + it('updates a mounted text component in place', function() {
31 + var el = document.createElement('div');
32 + var inst = React.render(<div>{'foo'}{'bar'}</div>, el);
33 +
34 + var foo = inst.getDOMNode().children[0];
35 + var bar = inst.getDOMNode().children[1];
36 + expect(foo.tagName).toBe('SPAN');
37 + expect(bar.tagName).toBe('SPAN');
38 +
39 + var inst = React.render(<div>{'baz'}{'qux'}</div>, el);
40 + // After the update, the spans should have stayed in place (as opposed to
41 + // getting unmounted and remounted)
42 + expect(inst.getDOMNode().children[0]).toBe(foo);
43 + expect(inst.getDOMNode().children[1]).toBe(bar);
44 + });
45 });