Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make test work in both Stack and Fiber
Stack uses comment nodes to key text nodes, but Fiber doesn't. The
test now works regardless.
  • Loading branch information
acdlite committed Feb 2, 2017
commit d11a20f9c6af6c8b61944d11d18afc7d070531ff
37 changes: 23 additions & 14 deletions src/renderers/shared/shared/__tests__/ReactMultiChildText-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,32 +224,41 @@ describe('ReactMultiChildText', () => {
it('should reorder keyed text nodes', () => {
spyOn(console, 'error');

function getAlphaAndBeta(nodes) {
var alpha;
var beta;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].textContent === 'alpha') {
alpha = nodes[i];
} else if (nodes[i].textContent === 'beta') {
beta = nodes[i];
}
}
return [alpha, beta];
}

var container = document.createElement('div');
ReactDOM.render(
<div>{new Map([['a', 'alpha'], ['b', 'beta']])}</div>,
container
);

var childNodes = container.firstChild.childNodes;
var alpha1 = childNodes[0];
var alpha2 = childNodes[1];
var alpha3 = childNodes[2];
var beta1 = childNodes[3];
var beta2 = childNodes[4];
var beta3 = childNodes[5];
var alphaAndBeta1 = getAlphaAndBeta(container.firstChild.childNodes);

expect(container.textContent).toEqual('alphabeta');
expect(alphaAndBeta1[0]).toBeDefined();
expect(alphaAndBeta1[1]).toBeDefined();

ReactDOM.render(
<div>{new Map([['b', 'beta'], ['a', 'alpha']])}</div>,
container
);

childNodes = container.firstChild.childNodes;
expect(childNodes[0]).toBe(beta1);
expect(childNodes[1]).toBe(beta2);
expect(childNodes[2]).toBe(beta3);
expect(childNodes[3]).toBe(alpha1);
expect(childNodes[4]).toBe(alpha2);
expect(childNodes[5]).toBe(alpha3);
var alphaAndBeta2 = getAlphaAndBeta(container.firstChild.childNodes);

expect(container.textContent).toEqual('betaalpha');
expect(alphaAndBeta1[0]).toBe(alphaAndBeta2[0]);
expect(alphaAndBeta1[1]).toBe(alphaAndBeta2[1]);

// Using Maps as children gives a single warning
expectDev(console.error.calls.count()).toBe(1);
Expand Down