Home / File/ ReactInternalTestUtils.js — react Source File

ReactInternalTestUtils.js — react Source File

Architecture documentation for ReactInternalTestUtils.js, a javascript file in the react codebase. 11 imports, 0 dependents.

File javascript BabelCompiler Entrypoint 11 imports 4 functions

Entity Profile

Dependency Diagram

graph LR
  29c464eb_52d1_465c_432a_544e82213726["ReactInternalTestUtils.js"]
  eb9fd692_9845_708f_0ef5_7de5736d7570["enqueueTask.js"]
  29c464eb_52d1_465c_432a_544e82213726 --> eb9fd692_9845_708f_0ef5_7de5736d7570
  25f70bd8_f112_d04a_4a3f_6a33aba6b460["simulateBrowserEventDispatch.js"]
  29c464eb_52d1_465c_432a_544e82213726 --> 25f70bd8_f112_d04a_4a3f_6a33aba6b460
  9565063b_3ea2_9cbf_86d6_3ee1e66bf4cc["consoleMock.js"]
  29c464eb_52d1_465c_432a_544e82213726 --> 9565063b_3ea2_9cbf_86d6_3ee1e66bf4cc
  dcab7879_15a5_b8dd_721e_6e835779837f["clearLogs"]
  29c464eb_52d1_465c_432a_544e82213726 --> dcab7879_15a5_b8dd_721e_6e835779837f
  215ba5c2_433a_0922_d95b_9b64d1bda54b["clearWarnings"]
  29c464eb_52d1_465c_432a_544e82213726 --> 215ba5c2_433a_0922_d95b_9b64d1bda54b
  daf494a6_d701_fe7c_a4a3_0560eead925b["clearErrors"]
  29c464eb_52d1_465c_432a_544e82213726 --> daf494a6_d701_fe7c_a4a3_0560eead925b
  05187c53_aa67_18f7_b65b_4debec66866c["createLogAssertion"]
  29c464eb_52d1_465c_432a_544e82213726 --> 05187c53_aa67_18f7_b65b_4debec66866c
  0aa66ba3_905d_182f_1981_1f2301583b90["internalAct.js"]
  29c464eb_52d1_465c_432a_544e82213726 --> 0aa66ba3_905d_182f_1981_1f2301583b90
  133f0f30_8ddf_1a39_c338_a2ba615827c0["unstable_mock"]
  29c464eb_52d1_465c_432a_544e82213726 --> 133f0f30_8ddf_1a39_c338_a2ba615827c0
  438ec5cd_e09b_6193_06b7_3753a896b547["jest-diff"]
  29c464eb_52d1_465c_432a_544e82213726 --> 438ec5cd_e09b_6193_06b7_3753a896b547
  b462ec7f_9e05_1754_ba7c_e890db2f44e8["expect-utils"]
  29c464eb_52d1_465c_432a_544e82213726 --> b462ec7f_9e05_1754_ba7c_e890db2f44e8
  style 29c464eb_52d1_465c_432a_544e82213726 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * 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.
 */

import * as SchedulerMock from 'scheduler/unstable_mock';
import {diff} from 'jest-diff';
import {equals} from '@jest/expect-utils';
import enqueueTask from './enqueueTask';
import simulateBrowserEventDispatch from './simulateBrowserEventDispatch';
import {
  clearLogs,
  clearWarnings,
  clearErrors,
  createLogAssertion,
} from './consoleMock';
export {getDebugInfo} from './debugInfo';
export {act, serverAct} from './internalAct';
const {assertConsoleLogsCleared} = require('internal-test-utils/consoleMock');

import {thrownErrors, actingUpdatesScopeDepth} from './internalAct';

function assertYieldsWereCleared(caller) {
  const actualYields = SchedulerMock.unstable_clearLog();
  if (actualYields.length !== 0) {
    const error = Error(
      'The event log is not empty. Call assertLog(...) first.',
    );
    Error.captureStackTrace(error, caller);
    throw error;
  }
  assertConsoleLogsCleared();
}

export async function waitForMicrotasks() {
  return new Promise(resolve => {
    enqueueTask(() => resolve());
  });
}

export async function waitFor(expectedLog, options) {
  assertYieldsWereCleared(waitFor);

  // Create the error object before doing any async work, to get a better
  // stack trace.
  const error = new Error();
  Error.captureStackTrace(error, waitFor);

  const stopAfter = expectedLog.length;
  const actualLog = [];
  do {
    // Wait until end of current task/microtask.
    await waitForMicrotasks();
    if (SchedulerMock.unstable_hasPendingWork()) {
      SchedulerMock.unstable_flushNumberOfYields(stopAfter - actualLog.length);
      actualLog.push(...SchedulerMock.unstable_clearLog());
      if (stopAfter > actualLog.length) {
        // Continue flushing until we've logged the expected number of items.
// ... (320 more lines)

Domain

Subdomains

Frequently Asked Questions

What does ReactInternalTestUtils.js do?
ReactInternalTestUtils.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Entrypoint subdomain.
What functions are defined in ReactInternalTestUtils.js?
ReactInternalTestUtils.js defines 4 function(s): assertYieldsWereCleared, waitFor, waitForAll, waitForMicrotasks.
What does ReactInternalTestUtils.js depend on?
ReactInternalTestUtils.js imports 11 module(s): clearErrors, clearLogs, clearWarnings, consoleMock.js, createLogAssertion, enqueueTask.js, expect-utils, internalAct.js, and 3 more.
Where is ReactInternalTestUtils.js in the architecture?
ReactInternalTestUtils.js is located at packages/internal-test-utils/ReactInternalTestUtils.js (domain: BabelCompiler, subdomain: Entrypoint, directory: packages/internal-test-utils).

Analyze Your Own Codebase

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

Try Supermodel Free