Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gnoff committed Jun 7, 2022
1 parent 2e78547 commit b952b61
Showing 1 changed file with 11 additions and 36 deletions.
47 changes: 11 additions & 36 deletions packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js
Expand Up @@ -11,7 +11,6 @@ let React;
let ReactDOMClient;
let ReactDOMServer;
let act;
let usingPartialRenderer;

const util = require('util');
const realConsoleError = console.error;
Expand All @@ -26,8 +25,6 @@ describe('ReactDOMServerHydration', () => {
ReactDOMServer = require('react-dom/server');
act = require('react-dom/test-utils').act;

usingPartialRenderer = global.__WWW__ && !__EXPERIMENTAL__;

console.error = jest.fn();
container = document.createElement('div');
document.body.appendChild(container);
Expand Down Expand Up @@ -731,15 +728,13 @@ describe('ReactDOMServerHydration', () => {
);
}

// @TODO FB bundles use a different renderer that does not serialize errors to the client
const mismatchEl = usingPartialRenderer ? '<p>' : '<template>';
// @TODO changes made to sending Fizz errors to client led to the insertion of templates in client rendered
// suspense boundaries. This leaks in this test becuase the client rendered suspense boundary appears like
// unhydrated tail nodes and this template is the first match. When we add special case handling for client
// rendered suspense boundaries this test will likely change again
expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
Array [
"Warning: Did not expect server HTML to contain a ${mismatchEl} in <div>.
"Warning: Did not expect server HTML to contain a <template> in <div>.
in div (at **)
in Mismatch (at **)",
"Warning: An error occurred during hydration. The server HTML was replaced with client content in <div>.",
Expand Down Expand Up @@ -819,21 +814,11 @@ describe('ReactDOMServerHydration', () => {
</div>
);
}
// We gate this assertion becuase fb-classic uses PartialRenderer for renderToString and it does not
// serialize server errors and send to client
if (usingPartialRenderer) {
expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
Array [
"Caught [The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering.]",
]
`);
} else {
expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
Array [
"Caught [The server did not finish this Suspense boundary: The server used \\"renderToString\\" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to \\"renderToPipeableStream\\" which supports Suspense on the server]",
]
`);
}
expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
Array [
"Caught [The server did not finish this Suspense boundary: The server used \\"renderToString\\" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to \\"renderToPipeableStream\\" which supports Suspense on the server]",
]
`);
});

// @gate __DEV__
Expand All @@ -854,21 +839,11 @@ describe('ReactDOMServerHydration', () => {
</div>
);
}
// We gate this assertion becuase fb-classic uses PartialRenderer for renderToString and it does not
// serialize server errors and send to client
if (usingPartialRenderer) {
expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
Array [
"Caught [The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering.]",
]
`);
} else {
expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
Array [
"Caught [The server did not finish this Suspense boundary: The server used \\"renderToString\\" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to \\"renderToPipeableStream\\" which supports Suspense on the server]",
]
`);
}
expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
Array [
"Caught [The server did not finish this Suspense boundary: The server used \\"renderToString\\" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to \\"renderToPipeableStream\\" which supports Suspense on the server]",
]
`);
});
});

Expand Down

0 comments on commit b952b61

Please sign in to comment.