Home / File/ reactTestMatchers.js — react Source File

reactTestMatchers.js — react Source File

Architecture documentation for reactTestMatchers.js, a javascript file in the react codebase.

Entity Profile

Relationship Graph

Source Code

'use strict';

const JestReact = require('jest-react');
const {assertConsoleLogsCleared} = require('internal-test-utils/consoleMock');
// TODO: Move to ReactInternalTestUtils

function captureAssertion(fn) {
  // Trick to use a Jest matcher inside another Jest matcher. `fn` contains an
  // assertion; if it throws, we capture the error and return it, so the stack
  // trace presented to the user points to the original assertion in the
  // test file.
  try {
    fn();
  } catch (error) {
    return {
      pass: false,
      message: () => error.message,
    };
  }
  return {pass: true};
}

function assertYieldsWereCleared(Scheduler, caller) {
  const actualYields = Scheduler.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();
}

function toMatchRenderedOutput(ReactNoop, expectedJSX) {
  if (typeof ReactNoop.getChildrenAsJSX === 'function') {
    const Scheduler = ReactNoop._Scheduler;
    assertYieldsWereCleared(Scheduler, toMatchRenderedOutput);
    return captureAssertion(() => {
      expect(ReactNoop.getChildrenAsJSX()).toEqual(expectedJSX);
    });
  }
  return JestReact.unstable_toMatchRenderedOutput(ReactNoop, expectedJSX);
}

module.exports = {
  toMatchRenderedOutput,
};

Domain

Subdomains

Frequently Asked Questions

What does reactTestMatchers.js do?
reactTestMatchers.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 reactTestMatchers.js?
reactTestMatchers.js defines 3 function(s): assertYieldsWereCleared, captureAssertion, toMatchRenderedOutput.
Where is reactTestMatchers.js in the architecture?
reactTestMatchers.js is located at scripts/jest/matchers/reactTestMatchers.js (domain: BabelCompiler, subdomain: Entrypoint, directory: scripts/jest/matchers).

Analyze Your Own Codebase

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

Try Supermodel Free