Skip to content

Commit

Permalink
test: Add smaller test for innerHTML=string to innerHTML=undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Apr 20, 2020
1 parent 63387c2 commit 5c05857
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ describe('ReactDOMServerHydration', () => {
expect(domElement.innerHTML).toEqual(markup);
});

it('should warns if innerHTML mismatches with dangerouslySetInnerHTML=undefined on the client', () => {
it('should warn if innerHTML mismatches with dangerouslySetInnerHTML=undefined and children on the client', () => {
const domElement = document.createElement('div');
const markup = ReactDOMServer.renderToStaticMarkup(
<div dangerouslySetInnerHTML={{__html: '<p>server</p>'}} />,
Expand All @@ -585,4 +585,20 @@ describe('ReactDOMServerHydration', () => {
'Warning: Text content did not match. Server: "server" Client: "client"',
);
});

it('should warn if innerHTML mismatches with dangerouslySetInnerHTML=undefined on the client', () => {
const domElement = document.createElement('div');
const markup = ReactDOMServer.renderToStaticMarkup(
<div dangerouslySetInnerHTML={{__html: '<p>server</p>'}} />,
);
domElement.innerHTML = markup;

expect(() => {
ReactDOM.hydrate(<div dangerouslySetInnerHTML={undefined} />, domElement);

expect(domElement.innerHTML).not.toEqual(markup);
}).toErrorDev(
'Warning: Did not expect server HTML to contain a <p> in <div>',
);
});
});

0 comments on commit 5c05857

Please sign in to comment.