Home / File/ setupTests.js — react Source File

setupTests.js — react Source File

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

Entity Profile

Relationship Graph

Source Code

'use strict';

const {getTestFlags} = require('./TestFlags');
const {
  assertConsoleLogsCleared,
  resetAllUnexpectedConsoleCalls,
  patchConsoleMethods,
} = require('internal-test-utils/consoleMock');
const path = require('path');

if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
  // Inside the class equivalence tester, we have a custom environment, let's
  // require that instead.
  require('./spec-equivalence-reporter/setupTests.js');
} else {
  const errorMap = require('../error-codes/codes.json');

  // By default, jest.spyOn also calls the spied method.
  const spyOn = jest.spyOn;
  const noop = jest.fn;

  // Can be used to normalize paths in stackframes
  global.__REACT_ROOT_PATH_TEST__ = path.resolve(__dirname, '../..');

  // Spying on console methods in production builds can mask errors.
  // This is why we added an explicit spyOnDev() helper.
  // It's too easy to accidentally use the more familiar spyOn() helper though,
  // So we disable it entirely.
  // Spying on both dev and prod will require using both spyOnDev() and spyOnProd().
  global.spyOn = function () {
    throw new Error(
      'Do not use spyOn(). ' +
        'It can accidentally hide unexpected errors in production builds. ' +
        'Use spyOnDev(), spyOnProd(), or spyOnDevAndProd() instead.'
    );
  };

  if (process.env.NODE_ENV === 'production') {
    global.spyOnDev = noop;
    global.spyOnProd = spyOn;
    global.spyOnDevAndProd = spyOn;
  } else {
    global.spyOnDev = spyOn;
    global.spyOnProd = noop;
    global.spyOnDevAndProd = spyOn;
  }

  expect.extend({
    ...require('./matchers/reactTestMatchers'),
    ...require('./matchers/toThrow'),
  });

  // We have a Babel transform that inserts guards against infinite loops.
  // If a loop runs for too many iterations, we throw an error and set this
  // global variable. The global lets us detect an infinite loop even if
  // the actual error object ends up being caught and ignored. An infinite
  // loop must always fail the test!
  beforeEach(() => {
    global.infiniteLoopError = null;
  });
// ... (273 more lines)

Domain

Subdomains

Frequently Asked Questions

What does setupTests.js do?
setupTests.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 setupTests.js?
setupTests.js defines 9 function(s): ErrorProxy.apply, ErrorProxy.construct, ErrorProxy.get, captureStackTrace, coerceGateConditionToFunction, decodeErrorMessage, expectTestToFail, global, proxyErrorInstance.
Where is setupTests.js in the architecture?
setupTests.js is located at scripts/jest/setupTests.js (domain: BabelCompiler, subdomain: Entrypoint, directory: scripts/jest).

Analyze Your Own Codebase

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

Try Supermodel Free