/** * Copyright (c) Meta Platforms, Inc. and 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 * @jest-environment ./scripts/jest/ReactDOMServerIntegrationEnvironment */ 'use strict'; const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); const TEXT_NODE_TYPE = 3; let React; let ReactDOMClient; let ReactDOMServer; function initModules() { // Reset warning cache. jest.resetModules(); React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); // Make them available to the helpers. return { ReactDOMClient, ReactDOMServer, }; } const {resetModules, itRenders} = ReactDOMServerIntegrationUtils(initModules); describe('ReactDOMServerIntegration', () => { beforeEach(() => { resetModules(); }); describe('basic rendering', function () { itRenders('a blank div', async render => { const e = await render(
); expect(e.tagName).toBe('DIV'); }); itRenders('a self-closing tag', async render => { const e = await render(
); expect(e.tagName).toBe('BR'); }); itRenders('a self-closing tag as a child', async render => { const e = await render(

, ); expect(e.childNodes.length).toBe(1); expect(e.firstChild.tagName).toBe('BR'); }); itRenders('a string', async render => { const e = await render('Hello'); expect(e.nodeType).toBe(3); expect(e.nodeValue).toMatch('Hello'); }); itRenders('a number', async render => { const e = await render(42); expect(e.nodeType).toBe(3); expect(e.nodeValue).toMatch('42'); }); itRenders('a bigint', async render => { const e = await render(42n); expect(e.nodeType).toBe(3); expect(e.nodeValue).toMatch('42'); }); itRenders('an array with one child', async render => { const e = await render([
text1
]); const parent = e.parentNode; expect(parent.childNodes[0].tagName).toBe('DIV'); }); itRenders('an array with several children', async render => { const Header = props => { return

header

; }; const Footer = props => { return [

footer

,

about

]; }; const e = await render([
text1
, text2,
,