Skip to content

Commit 509678d

Browse files
committed
Update tests that assert number of nodes
These tests are unnecessarily specific about number of nodes. I special case these, which these tests already do, because they're good tests to test that the optimization actually works later when we do fix it.
1 parent e915eee commit 509678d

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

packages/react-dom/src/__tests__/ReactDOMServerIntegrationElements-test.js

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('ReactDOMServerIntegration', () => {
101101
) {
102102
// For plain server markup result we have comments between.
103103
// If we're able to hydrate, they remain.
104-
expect(e.childNodes.length).toBe(5);
104+
expect(e.childNodes.length).toBe(render === streamRender ? 6 : 5);
105105
expectTextNode(e.childNodes[0], ' ');
106106
expectTextNode(e.childNodes[2], ' ');
107107
expectTextNode(e.childNodes[4], ' ');
@@ -119,8 +119,8 @@ describe('ReactDOMServerIntegration', () => {
119119
Text<span>More Text</span>
120120
</div>,
121121
);
122-
expect(e.childNodes.length).toBe(2);
123-
const spanNode = e.childNodes[1];
122+
expect(e.childNodes.length).toBe(render === streamRender ? 3 : 2);
123+
const spanNode = e.childNodes[render === streamRender ? 2 : 1];
124124
expectTextNode(e.childNodes[0], 'Text');
125125
expect(spanNode.tagName).toBe('SPAN');
126126
expect(spanNode.childNodes.length).toBe(1);
@@ -147,19 +147,19 @@ describe('ReactDOMServerIntegration', () => {
147147
itRenders('a custom element with text', async render => {
148148
const e = await render(<custom-element>Text</custom-element>);
149149
expect(e.tagName).toBe('CUSTOM-ELEMENT');
150-
expect(e.childNodes.length).toBe(1);
150+
expect(e.childNodes.length).toBe(render === streamRender ? 2 : 1);
151151
expectNode(e.firstChild, TEXT_NODE_TYPE, 'Text');
152152
});
153153

154154
itRenders('a leading blank child with a text sibling', async render => {
155155
const e = await render(<div>{''}foo</div>);
156-
expect(e.childNodes.length).toBe(1);
156+
expect(e.childNodes.length).toBe(render === streamRender ? 2 : 1);
157157
expectTextNode(e.childNodes[0], 'foo');
158158
});
159159

160160
itRenders('a trailing blank child with a text sibling', async render => {
161161
const e = await render(<div>foo{''}</div>);
162-
expect(e.childNodes.length).toBe(1);
162+
expect(e.childNodes.length).toBe(render === streamRender ? 2 : 1);
163163
expectTextNode(e.childNodes[0], 'foo');
164164
});
165165

@@ -176,7 +176,7 @@ describe('ReactDOMServerIntegration', () => {
176176
render === streamRender
177177
) {
178178
// In the server render output there's a comment between them.
179-
expect(e.childNodes.length).toBe(3);
179+
expect(e.childNodes.length).toBe(render === streamRender ? 4 : 3);
180180
expectTextNode(e.childNodes[0], 'foo');
181181
expectTextNode(e.childNodes[2], 'bar');
182182
} else {
@@ -203,7 +203,7 @@ describe('ReactDOMServerIntegration', () => {
203203
render === streamRender
204204
) {
205205
// In the server render output there's a comment between them.
206-
expect(e.childNodes.length).toBe(5);
206+
expect(e.childNodes.length).toBe(render === streamRender ? 6 : 5);
207207
expectTextNode(e.childNodes[0], 'a');
208208
expectTextNode(e.childNodes[2], 'b');
209209
expectTextNode(e.childNodes[4], 'c');
@@ -240,11 +240,7 @@ describe('ReactDOMServerIntegration', () => {
240240
e
241241
</div>,
242242
);
243-
if (
244-
render === serverRender ||
245-
render === clientRenderOnServerString ||
246-
render === streamRender
247-
) {
243+
if (render === serverRender || render === clientRenderOnServerString) {
248244
// In the server render output there's comments between text nodes.
249245
expect(e.childNodes.length).toBe(5);
250246
expectTextNode(e.childNodes[0], 'a');
@@ -253,6 +249,15 @@ describe('ReactDOMServerIntegration', () => {
253249
expectTextNode(e.childNodes[3].childNodes[0], 'c');
254250
expectTextNode(e.childNodes[3].childNodes[2], 'd');
255251
expectTextNode(e.childNodes[4], 'e');
252+
} else if (render === streamRender) {
253+
// In the server render output there's comments after each text node.
254+
expect(e.childNodes.length).toBe(7);
255+
expectTextNode(e.childNodes[0], 'a');
256+
expectTextNode(e.childNodes[2], 'b');
257+
expect(e.childNodes[4].childNodes.length).toBe(4);
258+
expectTextNode(e.childNodes[4].childNodes[0], 'c');
259+
expectTextNode(e.childNodes[4].childNodes[2], 'd');
260+
expectTextNode(e.childNodes[5], 'e');
256261
} else {
257262
expect(e.childNodes.length).toBe(4);
258263
expectTextNode(e.childNodes[0], 'a');
@@ -291,7 +296,7 @@ describe('ReactDOMServerIntegration', () => {
291296
render === streamRender
292297
) {
293298
// In the server markup there's a comment between.
294-
expect(e.childNodes.length).toBe(3);
299+
expect(e.childNodes.length).toBe(render === streamRender ? 4 : 3);
295300
expectTextNode(e.childNodes[0], 'foo');
296301
expectTextNode(e.childNodes[2], '40');
297302
} else {
@@ -330,13 +335,13 @@ describe('ReactDOMServerIntegration', () => {
330335

331336
itRenders('null children as blank', async render => {
332337
const e = await render(<div>{null}foo</div>);
333-
expect(e.childNodes.length).toBe(1);
338+
expect(e.childNodes.length).toBe(render === streamRender ? 2 : 1);
334339
expectTextNode(e.childNodes[0], 'foo');
335340
});
336341

337342
itRenders('false children as blank', async render => {
338343
const e = await render(<div>{false}foo</div>);
339-
expect(e.childNodes.length).toBe(1);
344+
expect(e.childNodes.length).toBe(render === streamRender ? 2 : 1);
340345
expectTextNode(e.childNodes[0], 'foo');
341346
});
342347

@@ -348,7 +353,7 @@ describe('ReactDOMServerIntegration', () => {
348353
{false}
349354
</div>,
350355
);
351-
expect(e.childNodes.length).toBe(1);
356+
expect(e.childNodes.length).toBe(render === streamRender ? 2 : 1);
352357
expectTextNode(e.childNodes[0], 'foo');
353358
});
354359

@@ -735,10 +740,10 @@ describe('ReactDOMServerIntegration', () => {
735740
</div>,
736741
);
737742
expect(e.id).toBe('parent');
738-
expect(e.childNodes.length).toBe(3);
743+
expect(e.childNodes.length).toBe(render === streamRender ? 4 : 3);
739744
const child1 = e.childNodes[0];
740745
const textNode = e.childNodes[1];
741-
const child2 = e.childNodes[2];
746+
const child2 = e.childNodes[render === streamRender ? 3 : 2];
742747
expect(child1.id).toBe('child1');
743748
expect(child1.childNodes.length).toBe(0);
744749
expectTextNode(textNode, ' ');
@@ -752,10 +757,10 @@ describe('ReactDOMServerIntegration', () => {
752757
async render => {
753758
// prettier-ignore
754759
const e = await render(<div id="parent"> <div id="child" /> </div>); // eslint-disable-line no-multi-spaces
755-
expect(e.childNodes.length).toBe(3);
760+
expect(e.childNodes.length).toBe(render === streamRender ? 5 : 3);
756761
const textNode1 = e.childNodes[0];
757-
const child = e.childNodes[1];
758-
const textNode2 = e.childNodes[2];
762+
const child = e.childNodes[render === streamRender ? 2 : 1];
763+
const textNode2 = e.childNodes[render === streamRender ? 3 : 2];
759764
expect(e.id).toBe('parent');
760765
expectTextNode(textNode1, ' ');
761766
expect(child.id).toBe('child');
@@ -778,7 +783,9 @@ describe('ReactDOMServerIntegration', () => {
778783
) {
779784
// For plain server markup result we have comments between.
780785
// If we're able to hydrate, they remain.
781-
expect(parent.childNodes.length).toBe(5);
786+
expect(parent.childNodes.length).toBe(
787+
render === streamRender ? 6 : 5,
788+
);
782789
expectTextNode(parent.childNodes[0], 'a');
783790
expectTextNode(parent.childNodes[2], 'b');
784791
expectTextNode(parent.childNodes[4], 'c');
@@ -810,7 +817,7 @@ describe('ReactDOMServerIntegration', () => {
810817
render === clientRenderOnServerString ||
811818
render === streamRender
812819
) {
813-
expect(e.childNodes.length).toBe(3);
820+
expect(e.childNodes.length).toBe(render === streamRender ? 4 : 3);
814821
expectTextNode(e.childNodes[0], '<span>Text1&quot;</span>');
815822
expectTextNode(e.childNodes[2], '<span>Text2&quot;</span>');
816823
} else {
@@ -861,7 +868,7 @@ describe('ReactDOMServerIntegration', () => {
861868
);
862869
if (render === serverRender || render === streamRender) {
863870
// We have three nodes because there is a comment between them.
864-
expect(e.childNodes.length).toBe(3);
871+
expect(e.childNodes.length).toBe(render === streamRender ? 4 : 3);
865872
// Everything becomes LF when parsed from server HTML.
866873
// Null character is ignored.
867874
expectNode(e.childNodes[0], TEXT_NODE_TYPE, 'foo\nbar');

0 commit comments

Comments
 (0)