Skip to content

Commit 24ea3aa

Browse files
Update tests for streamServerRenderedReactComponent to improve chunk validation and error handling messages
1 parent 35532a8 commit 24ea3aa

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

node_package/tests/streamServerRenderedReactComponent.test.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ describe('streamServerRenderedReactComponent', () => {
170170
});
171171

172172
expect(onError).toHaveBeenCalled();
173-
expect(chunks).toHaveLength(2);
173+
expect(chunks.length).toBeGreaterThanOrEqual(2);
174174
expect(chunks[0].html).toContain('Header In The Shell');
175175
expect(chunks[0].consoleReplayScript).toBe('');
176176
expect(chunks[0].hasErrors).toBe(false);
177177
expect(chunks[0].isShellReady).toBe(true);
178178
// Script that fallbacks the render to client side
179-
expect(chunks[1].html).toMatch(/<script>[.\s\S]*Async Error[.\s\S]*<\/script>/);
179+
expect(chunks[1].html).toMatch(/the server rendering errored:\\n\\nAsync Error/);
180180
expect(chunks[1].consoleReplayScript).toBe('');
181181
expect(chunks[1].hasErrors).toBe(true);
182182
expect(chunks[1].isShellReady).toBe(true);
@@ -191,13 +191,13 @@ describe('streamServerRenderedReactComponent', () => {
191191
});
192192

193193
expect(onError).not.toHaveBeenCalled();
194-
expect(chunks).toHaveLength(2);
194+
expect(chunks.length).toBeGreaterThanOrEqual(2);
195195
expect(chunks[0].html).toContain('Header In The Shell');
196196
expect(chunks[0].consoleReplayScript).toBe('');
197197
expect(chunks[0].hasErrors).toBe(false);
198198
expect(chunks[0].isShellReady).toBe(true);
199199
// Script that fallbacks the render to client side
200-
expect(chunks[1].html).toMatch(/<script>[.\s\S]*Async Error[.\s\S]*<\/script>/);
200+
expect(chunks[1].html).toMatch(/the server rendering errored:\\n\\nAsync Error/);
201201
expect(chunks[1].consoleReplayScript).toBe('');
202202
expect(chunks[1].hasErrors).toBe(true);
203203
expect(chunks[1].isShellReady).toBe(true);
@@ -241,12 +241,12 @@ describe('streamServerRenderedReactComponent', () => {
241241
const { renderResult, chunks } = setupStreamTest({ componentType, throwAsyncError: true });
242242
await new Promise((resolve) => renderResult.on('end', resolve));
243243

244-
expect(chunks).toHaveLength(2);
244+
expect(chunks.length).toBeGreaterThanOrEqual(2);
245245
expect(chunks[0].html).toContain('Header In The Shell');
246246
expect(chunks[0].consoleReplayScript).toBe('');
247247
expect(chunks[0].hasErrors).toBe(false);
248248
expect(chunks[0].isShellReady).toBe(true);
249-
expect(chunks[1].html).toMatch(/<script>[.\s\S]*Async Error[.\s\S]*<\/script>/);
249+
expect(chunks[1].html).toMatch(/the server rendering errored:\\n\\nAsync Error/);
250250
expect(chunks[1].consoleReplayScript).toBe('');
251251
expect(chunks[1].hasErrors).toBe(true);
252252
expect(chunks[1].isShellReady).toBe(true);

0 commit comments

Comments
 (0)