MCPcopy
hub / github.com/facebook/react / captureAssertion

Function captureAssertion

scripts/jest/matchers/reactTestMatchers.js:7–21  ·  view source on GitHub ↗
(fn)

Source from the content-addressed store, hash-verified

5// TODO: Move to ReactInternalTestUtils
6
7function captureAssertion(fn) {
8 // Trick to use a Jest matcher inside another Jest matcher. `fn` contains an
9 // assertion; if it throws, we capture the error and return it, so the stack
10 // trace presented to the user points to the original assertion in the
11 // test file.
12 try {
13 fn();
14 } catch (error) {
15 return {
16 pass: false,
17 message: () => error.message,
18 };
19 }
20 return {pass: true};
21}
22
23function assertYieldsWereCleared(Scheduler, caller) {
24 const actualYields = Scheduler.unstable_clearLog();

Callers 1

toMatchRenderedOutputFunction · 0.70

Calls 1

fnFunction · 0.50

Tested by

no test coverage detected