/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/
'use strict';
const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils');
let React;
let ReactDOM;
let ReactDOMServer;
function initModules() {
// Reset warning cache.
jest.resetModuleRegistry();
React = require('react');
ReactDOM = require('react-dom');
ReactDOMServer = require('react-dom/server');
// Make them available to the helpers.
return {
ReactDOM,
ReactDOMServer,
};
}
const {
resetModules,
expectMarkupMismatch,
expectMarkupMatch,
} = ReactDOMServerIntegrationUtils(initModules);
describe('ReactDOMServerIntegration', () => {
beforeEach(() => {
resetModules();
});
describe('reconnecting to server markup', function() {
let EmptyComponent;
beforeEach(() => {
EmptyComponent = class extends React.Component {
render() {
return null;
}
};
});
describe('elements', function() {
describe('reconnecting different component implementations', function() {
let ES6ClassComponent, PureComponent, bareElement;
beforeEach(() => {
// try each type of component on client and server.
ES6ClassComponent = class extends React.Component {
render() {
return
;
}
};
PureComponent = props => ;
bareElement = ;
});
it('should reconnect ES6 Class to ES6 Class', () =>
expectMarkupMatch(
,
,
));
it('should reconnect Pure Component to ES6 Class', () =>
expectMarkupMatch(
,
,
));
it('should reconnect Bare Element to ES6 Class', () =>
expectMarkupMatch(, bareElement));
it('should reconnect ES6 Class to Pure Component', () =>
expectMarkupMatch(
,
,
));
it('should reconnect Pure Component to Pure Component', () =>
expectMarkupMatch(
,
,
));
it('should reconnect Bare Element to Pure Component', () =>
expectMarkupMatch(, bareElement));
it('should reconnect ES6 Class to Bare Element', () =>
expectMarkupMatch(bareElement, ));
it('should reconnect Pure Component to Bare Element', () =>
expectMarkupMatch(bareElement, ));
it('should reconnect Bare Element to Bare Element', () =>
expectMarkupMatch(bareElement, bareElement));
});
it('should error reconnecting different element types', () =>
expectMarkupMismatch(, ));
it('should error reconnecting fewer root children', () =>
expectMarkupMismatch(, [
,
,
]));
it('should error reconnecting missing attributes', () =>
expectMarkupMismatch(, ));
it('should error reconnecting added attributes', () =>
expectMarkupMismatch(, ));
it('should error reconnecting different attribute values', () =>
expectMarkupMismatch(, ));
it('can explicitly ignore errors reconnecting different element types of children', () =>
expectMarkupMatch(
,
,
));
it('can explicitly ignore errors reconnecting missing attributes', () =>
expectMarkupMatch(
,
,
));
it('can explicitly ignore errors reconnecting added attributes', () =>
expectMarkupMatch(
,
,
));
it('can explicitly ignore errors reconnecting different attribute values', () =>
expectMarkupMatch(
,
,
));
it('can not deeply ignore errors reconnecting different attribute values', () =>
expectMarkupMismatch(
,
,
));
});
describe('inline styles', function() {
it('should error reconnecting missing style attribute', () =>
expectMarkupMismatch(, ));
it('should error reconnecting added style attribute', () =>
expectMarkupMismatch(, ));
it('should error reconnecting empty style attribute', () =>
expectMarkupMismatch(
,
,
));
it('should error reconnecting added style values', () =>
expectMarkupMismatch(
,
,
));
it('should error reconnecting different style values', () =>
expectMarkupMismatch(
,
,
));
it('should reconnect number and string versions of a number', () =>
expectMarkupMatch(
,
,
));
it('should error reconnecting reordered style values', () =>
expectMarkupMismatch(
,
,
));
it('can explicitly ignore errors reconnecting added style values', () =>
expectMarkupMatch(
,
,
));
it('can explicitly ignore reconnecting different style values', () =>
expectMarkupMatch(
,
,
));
});
describe('text nodes', function() {
it('should error reconnecting different text', () =>
expectMarkupMismatch(Text
, Other Text
));
it('should reconnect a div with a number and string version of number', () =>
expectMarkupMatch({2}
, 2
));
it('should error reconnecting different numbers', () =>
expectMarkupMismatch({2}
, {3}
));
it('should error reconnecting different number from text', () =>
expectMarkupMismatch({2}
, 3
));
it('should error reconnecting different text in two code blocks', () =>
expectMarkupMismatch(
{'Text1'}
{'Text2'}
,
{'Text1'}
{'Text3'}
,
));
it('can explicitly ignore reconnecting different text', () =>
expectMarkupMatch(
Text
,
Other Text
,
));
it('can explicitly ignore reconnecting different text in two code blocks', () =>
expectMarkupMatch(
{'Text1'}
{'Text2'}
,
{'Text1'}
{'Text3'}
,
));
});
describe('element trees and children', function() {
it('should error reconnecting missing children', () =>
expectMarkupMismatch(
,
,
));
it('should error reconnecting added children', () =>
expectMarkupMismatch(
,
,
));
it('should error reconnecting more children', () =>
expectMarkupMismatch(
,
,
));
it('should error reconnecting fewer children', () =>
expectMarkupMismatch(
,
,
));
it('should error reconnecting reordered children', () =>
expectMarkupMismatch(
,
,
));
it('should error reconnecting a div with children separated by whitespace on the client', () =>
expectMarkupMismatch(
,
// prettier-ignore
, // eslint-disable-line no-multi-spaces
));
it('should error reconnecting a div with children separated by different whitespace on the server', () =>
expectMarkupMismatch(
// prettier-ignore
, // eslint-disable-line no-multi-spaces
,
));
it('should error reconnecting a div with children separated by different whitespace', () =>
expectMarkupMismatch(
,
// prettier-ignore
, // eslint-disable-line no-multi-spaces
));
it('can distinguish an empty component from a dom node', () =>
expectMarkupMismatch(
,
,
));
it('can distinguish an empty component from an empty text component', () =>
expectMarkupMatch(
,
{''}
,
));
it('can explicitly ignore reconnecting more children', () =>
expectMarkupMatch(
,
,
));
it('can explicitly ignore reconnecting fewer children', () =>
expectMarkupMatch(
,
,
));
it('can explicitly ignore reconnecting reordered children', () =>
expectMarkupMatch(
,
,
));
it('can not deeply ignore reconnecting reordered children', () =>
expectMarkupMismatch(
,
,
));
});
// Markup Mismatches: misc
it('should error reconnecting a div with different dangerouslySetInnerHTML', () =>
expectMarkupMismatch(
"}} />,
"}} />,
));
it('should error reconnecting a div with different text dangerouslySetInnerHTML', () =>
expectMarkupMismatch(
,
,
));
it('should error reconnecting a div with different number dangerouslySetInnerHTML', () =>
expectMarkupMismatch(
,
,
));
it('should error reconnecting a div with different object dangerouslySetInnerHTML', () =>
expectMarkupMismatch(
,
,
));
it('can explicitly ignore reconnecting a div with different dangerouslySetInnerHTML', () =>
expectMarkupMatch(
"}} />,
"}}
suppressHydrationWarning={true}
/>,
));
});
});