Home / Function/ captureAssertion() — react Function Reference

captureAssertion() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  5d8d65b2_75e4_f1b1_07c6_d6f74b221cad["captureAssertion()"]
  6e8c1123_cee1_9b1d_49c3_11cbcce7cb2e["JestReact.js"]
  5d8d65b2_75e4_f1b1_07c6_d6f74b221cad -->|defined in| 6e8c1123_cee1_9b1d_49c3_11cbcce7cb2e
  02ba167f_fe6e_f314_15bd_26d5552907e9["unstable_toMatchRenderedOutput()"]
  02ba167f_fe6e_f314_15bd_26d5552907e9 -->|calls| 5d8d65b2_75e4_f1b1_07c6_d6f74b221cad
  style 5d8d65b2_75e4_f1b1_07c6_d6f74b221cad fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/jest-react/src/JestReact.js lines 13–27

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 packages/jest-react/src/JestReact.js.
Where is captureAssertion() defined?
captureAssertion() is defined in packages/jest-react/src/JestReact.js at line 13.
What calls captureAssertion()?
captureAssertion() is called by 1 function(s): unstable_toMatchRenderedOutput.

Analyze Your Own Codebase

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

Try Supermodel Free