Skip to content

Commit

Permalink
Failing test for ignored suppressHydrationWarning using hydrateRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Silbermann committed Nov 4, 2022
1 parent bdd3d08 commit 0cb2202
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegratio

let React;
let ReactDOM;
let ReactDOMClient;
let ReactDOMServer;
let ReactTestUtils;
let act;

function initModules() {
// Reset warning cache.
jest.resetModuleRegistry();

React = require('react');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
ReactDOMServer = require('react-dom/server');
ReactTestUtils = require('react-dom/test-utils');
act = require('jest-react').act;

// Make them available to the helpers.
return {
Expand Down Expand Up @@ -357,6 +361,30 @@ describe('ReactDOMServerIntegration', () => {
<div>{''}</div>,
));

it('can explicitly ignore reconnecting new children', async () => {
const container = document.createElement('div');
container.innerHTML = ReactDOMServer.renderToString(
<div suppressHydrationWarning={true}>{null}</div>,
);

const recoverableErrors = [];
act(() => {
ReactDOMClient.hydrateRoot(
container,
<div suppressHydrationWarning={true}>
<p>Hello, Dave!</p>
</div>,
{
onRecoverableError: error => {
recoverableErrors.push(error);
},
},
);
});

expect(recoverableErrors).toEqual([]);
});

it('can explicitly ignore reconnecting more children', () =>
expectMarkupMatch(
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,5 +384,7 @@ module.exports = function(initModules) {
clientRenderOnServerString,
renderIntoDom,
streamRender,
ReactDOMServer,
ReactDOM,
};
};

0 comments on commit 0cb2202

Please sign in to comment.