Home / Function/ module() — react Function Reference

module() — react Function Reference

Architecture documentation for the module() function in ReactDOMServerIntegrationTestUtils.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  3c26b402_b44f_174f_9615_4d2c017278b6["module()"]
  b5d06153_dcd4_9917_8ab5_8f4ccf09455a["ReactDOMServerIntegrationTestUtils.js"]
  3c26b402_b44f_174f_9615_4d2c017278b6 -->|defined in| b5d06153_dcd4_9917_8ab5_8f4ccf09455a
  7e54494f_ebd1_99d9_3584_b3cf126e1c82["constructor()"]
  3c26b402_b44f_174f_9615_4d2c017278b6 -->|calls| 7e54494f_ebd1_99d9_3584_b3cf126e1c82
  8555564d_9ae0_f176_9061_248dc1ce8ba1["_write()"]
  3c26b402_b44f_174f_9615_4d2c017278b6 -->|calls| 8555564d_9ae0_f176_9061_248dc1ce8ba1
  style 3c26b402_b44f_174f_9615_4d2c017278b6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-dom/src/__tests__/utils/ReactDOMServerIntegrationTestUtils.js lines 15–408

module.exports = function (initModules) {
  let ReactDOM;
  let ReactDOMClient;
  let ReactDOMServer;
  let act;

  function resetModules() {
    ({ReactDOM, ReactDOMClient, ReactDOMServer} = initModules());
    act = require('internal-test-utils').act;
  }

  function shouldUseDocument(reactElement) {
    // Used for whole document tests.
    return reactElement && reactElement.type === 'html';
  }

  function getContainerFromMarkup(reactElement, markup) {
    if (shouldUseDocument(reactElement)) {
      const doc = document.implementation.createHTMLDocument('');
      doc.open();
      doc.write(
        markup ||
          '<!doctype html><html><meta charset=utf-8><title>test doc</title>',
      );
      doc.close();
      return doc;
    } else {
      const container = document.createElement('div');
      container.innerHTML = markup;
      return container;
    }
  }

  // Helper functions for rendering tests
  // ====================================

  // promisified version of ReactDOM.render()
  async function asyncReactDOMRender(reactElement, domElement, forceHydrate) {
    if (forceHydrate) {
      await act(() => {
        ReactDOMClient.hydrateRoot(domElement, reactElement, {
          onRecoverableError(e) {
            if (
              e.message.startsWith(
                'There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.',
              )
            ) {
              // We ignore this extra error because it shouldn't really need to be there if
              // a hydration mismatch is the cause of it.
            } else {
              console.error(e);
            }
          },
        });
      });
    } else {
      await act(() => {
        if (ReactDOMClient) {
          const root = ReactDOMClient.createRoot(domElement);
          root.render(reactElement);
        } else {
          ReactDOM.render(reactElement, domElement);
        }
      });
    }
  }
  // performs fn asynchronously and expects count errors logged to console.error.
  // will fail the test if the count of errors logged is not equal to count.
  async function expectErrors(fn, count) {
    if (console.error.mockClear) {
      console.error.mockClear();
    } else {
      // TODO: Rewrite tests that use this helper to enumerate expected errors.
      // This will enable the helper to use the assertConsoleErrorDev instead of spying.
      spyOnDev(console, 'error').mockImplementation(() => {});
    }

    const result = await fn();
    if (
      console.error.mock &&
      console.error.mock.calls &&

Domain

Subdomains

Frequently Asked Questions

What does module() do?
module() is a function in the react codebase, defined in packages/react-dom/src/__tests__/utils/ReactDOMServerIntegrationTestUtils.js.
Where is module() defined?
module() is defined in packages/react-dom/src/__tests__/utils/ReactDOMServerIntegrationTestUtils.js at line 15.
What does module() call?
module() calls 2 function(s): _write, constructor.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free