Home / Function/ captureAssertion() — react Function Reference

captureAssertion() — react Function Reference

Architecture documentation for the captureAssertion() function in reactTestMatchers.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  54d4b321_4d14_1f1b_b941_7337c643b772["captureAssertion()"]
  3d868c1f_a0e6_ed76_347e_51c4c370a7b5["reactTestMatchers.js"]
  54d4b321_4d14_1f1b_b941_7337c643b772 -->|defined in| 3d868c1f_a0e6_ed76_347e_51c4c370a7b5
  5cb4ccde_ac4d_2440_88a3_2b9f5a5d3c26["toMatchRenderedOutput()"]
  5cb4ccde_ac4d_2440_88a3_2b9f5a5d3c26 -->|calls| 54d4b321_4d14_1f1b_b941_7337c643b772
  style 54d4b321_4d14_1f1b_b941_7337c643b772 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

scripts/jest/matchers/reactTestMatchers.js lines 7–21

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};
}

Domain

Subdomains

Frequently Asked Questions

What does captureAssertion() do?
captureAssertion() is a function in the react codebase, defined in scripts/jest/matchers/reactTestMatchers.js.
Where is captureAssertion() defined?
captureAssertion() is defined in scripts/jest/matchers/reactTestMatchers.js at line 7.
What calls captureAssertion()?
captureAssertion() is called by 1 function(s): toMatchRenderedOutput.

Analyze Your Own Codebase

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

Try Supermodel Free