Skip to content

Commit

Permalink
Add test for rendering over pre-rendered text nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
mwiencek committed Dec 30, 2015
1 parent 721b489 commit 9238567
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/renderers/dom/shared/__tests__/ReactDOMTextComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@

var React;
var ReactDOM;
var ReactDOMServer;

describe('ReactDOMTextComponent', function() {
beforeEach(function() {
React = require('React');
ReactDOM = require('ReactDOM');
ReactDOMServer = require('ReactDOMServer');
});

it('updates a mounted text component in place', function() {
Expand Down Expand Up @@ -90,4 +92,26 @@ describe('ReactDOMTextComponent', function() {
inst = ReactDOM.render(<div><span />{'bar'}</div>, el);
expect(textNode.data).toBe('bar');
});

it('are preserved in pre-rendered markup', function() {
var el = document.createElement('div');
var reactElements = <div>{'foo'}<span key={0} />{'bar'}<span key={1} />{'baz'}</div>;
el.innerHTML = ReactDOMServer.renderToString(reactElements);

var childNodes = el.childNodes[0].childNodes;
var text1 = childNodes[0];
var span1 = childNodes[1];
var text2 = childNodes[2];
var span2 = childNodes[3];
var text3 = childNodes[4];

var inst = ReactDOM.render(reactElements, el);
childNodes = ReactDOM.findDOMNode(inst).childNodes;
expect(childNodes.length).toBe(5);
expect(childNodes[0]).toBe(text1);
expect(childNodes[1]).toBe(span1);
expect(childNodes[2]).toBe(text2);
expect(childNodes[3]).toBe(span2);
expect(childNodes[4]).toBe(text3);
});
});

0 comments on commit 9238567

Please sign in to comment.