Skip to content

Commit ad10b0c

Browse files
fix failing jest tests
1 parent 63d86d8 commit ad10b0c

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

node_package/tests/SuspenseHydration.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ const AsyncComponentContainer = ({
4545
});
4646
return (
4747
<Suspense fallback={<div>Loading...</div>}>
48-
{/* @ts-expect-error - This is a test */}
4948
<AsyncComponent promise={promise} onRendered={onAsyncComponentRendered} />
5049
</Suspense>
5150
);

node_package/tests/injectRSCPayload.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ describe('injectRSCPayload', () => {
9393
expect(resultStr).toEqual(
9494
'<html><body><div>Hello, world!</div></body></html>' +
9595
'<div>Next chunk</div>' +
96-
`<script>((self.REACT_ON_RAILS_RSC_PAYLOADS||={})["test-{}-123"]||=[]).push("{\\"test\\": \\"data\\"}")</script>` +
97-
`<script>((self.REACT_ON_RAILS_RSC_PAYLOADS||={})["test-{}-123"]||=[]).push("{\\"test\\": \\"data2\\"}")</script>`,
96+
'<script>(self.REACT_ON_RAILS_RSC_PAYLOADS||={})["test-{}-123"]||=[]</script>' +
97+
'<script>((self.REACT_ON_RAILS_RSC_PAYLOADS||={})["test-{}-123"]||=[]).push("{\\"test\\": \\"data\\"}")</script>' +
98+
'<script>((self.REACT_ON_RAILS_RSC_PAYLOADS||={})["test-{}-123"]||=[]).push("{\\"test\\": \\"data2\\"}")</script>',
9899
);
99100
});
100101

@@ -111,8 +112,9 @@ describe('injectRSCPayload', () => {
111112

112113
expect(resultStr).toEqual(
113114
'<html><body><div>Hello, world!</div></body></html>' +
114-
`<script>((self.REACT_ON_RAILS_RSC_PAYLOADS||={})["test-{}-123"]||=[]).push("{\\"test\\": \\"data\\"}")</script>` +
115-
`<script>((self.REACT_ON_RAILS_RSC_PAYLOADS||={})["test-{}-123"]||=[]).push("{\\"test\\": \\"data2\\"}")</script>` +
115+
'<script>(self.REACT_ON_RAILS_RSC_PAYLOADS||={})["test-{}-123"]||=[]</script>' +
116+
'<script>((self.REACT_ON_RAILS_RSC_PAYLOADS||={})["test-{}-123"]||=[]).push("{\\"test\\": \\"data\\"}")</script>' +
117+
'<script>((self.REACT_ON_RAILS_RSC_PAYLOADS||={})["test-{}-123"]||=[]).push("{\\"test\\": \\"data2\\"}")</script>' +
116118
'<div>Next chunk</div>',
117119
);
118120
});
@@ -134,8 +136,9 @@ describe('injectRSCPayload', () => {
134136
expect(resultStr).toEqual(
135137
'<html><body><div>Hello, world!</div></body></html>' +
136138
'<div>Next chunk</div>' +
137-
`<script>((self.REACT_ON_RAILS_RSC_PAYLOADS||={})["test-{}-123"]||=[]).push("{\\"test\\": \\"data\\"}")</script>` +
138-
`<script>((self.REACT_ON_RAILS_RSC_PAYLOADS||={})["test-{}-123"]||=[]).push("{\\"test\\": \\"data2\\"}")</script>` +
139+
'<script>(self.REACT_ON_RAILS_RSC_PAYLOADS||={})["test-{}-123"]||=[]</script>' +
140+
'<script>((self.REACT_ON_RAILS_RSC_PAYLOADS||={})["test-{}-123"]||=[]).push("{\\"test\\": \\"data\\"}")</script>' +
141+
'<script>((self.REACT_ON_RAILS_RSC_PAYLOADS||={})["test-{}-123"]||=[]).push("{\\"test\\": \\"data2\\"}")</script>' +
139142
'<div>Third chunk</div>',
140143
);
141144
});

node_package/tests/streamServerRenderedReactComponent.test.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ReactOnRails from '../src/ReactOnRails.node.ts';
1010

1111
const AsyncContent = async ({ throwAsyncError }) => {
1212
await new Promise((resolve) => {
13-
setTimeout(resolve, 0);
13+
setTimeout(resolve, 10);
1414
});
1515
if (throwAsyncError) {
1616
throw new Error('Async Error');
@@ -176,7 +176,7 @@ describe('streamServerRenderedReactComponent', () => {
176176
});
177177

178178
expect(onError).toHaveBeenCalled();
179-
expect(chunks.length).toBeGreaterThanOrEqual(2);
179+
expect(chunks).toHaveLength(2);
180180
expect(chunks[0].html).toContain('Header In The Shell');
181181
expect(chunks[0].consoleReplayScript).toBe('');
182182
expect(chunks[0].isShellReady).toBe(true);
@@ -188,7 +188,7 @@ describe('streamServerRenderedReactComponent', () => {
188188
// One of the chunks should have a hasErrors property of true
189189
expect(chunks[0].hasErrors || chunks[1].hasErrors).toBe(true);
190190
expect(chunks[0].hasErrors && chunks[1].hasErrors).toBe(false);
191-
});
191+
}, 100000);
192192

193193
it("doesn't emit an error if there is an error in the async content and throwJsErrors is false", async () => {
194194
const { renderResult, chunks } = setupStreamTest({ throwAsyncError: true, throwJsErrors: false });

0 commit comments

Comments
 (0)