createMatcherFor() — react Function Reference
Architecture documentation for the createMatcherFor() function in setupTests.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 2ee06bbb_2a80_cd1f_54d6_471ebbcb13a4["createMatcherFor()"] 4bb57a78_6434_ff0e_5a01_a28eed969531["setupTests.js"] 2ee06bbb_2a80_cd1f_54d6_471ebbcb13a4 -->|defined in| 4bb57a78_6434_ff0e_5a01_a28eed969531 60dbaa76_e574_2a7d_2ea1_7c598d65d949["shouldIgnoreConsoleError()"] 2ee06bbb_2a80_cd1f_54d6_471ebbcb13a4 -->|calls| 60dbaa76_e574_2a7d_2ea1_7c598d65d949 d53bf53d_68b8_e008_bd7b_2c95c71cafd5["normalizeCodeLocInfo()"] 2ee06bbb_2a80_cd1f_54d6_471ebbcb13a4 -->|calls| d53bf53d_68b8_e008_bd7b_2c95c71cafd5 style 2ee06bbb_2a80_cd1f_54d6_471ebbcb13a4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
fixtures/legacy-jsx-runtimes/setupTests.js lines 57–303
const createMatcherFor = (consoleMethod, matcherName) =>
function matcher(callback, expectedMessages, options = {}) {
if (process.env.NODE_ENV !== 'production') {
// Warn about incorrect usage of matcher.
if (typeof expectedMessages === 'string') {
expectedMessages = [expectedMessages];
} else if (!Array.isArray(expectedMessages)) {
throw Error(
`${matcherName}() requires a parameter of type string or an array of strings ` +
`but was given ${typeof expectedMessages}.`
);
}
if (
options != null &&
(typeof options !== 'object' || Array.isArray(options))
) {
throw new Error(
`${matcherName}() second argument, when present, should be an object. ` +
'Did you forget to wrap the messages into an array?'
);
}
if (arguments.length > 3) {
// `matcher` comes from Jest, so it's more than 2 in practice
throw new Error(
`${matcherName}() received more than two arguments. ` +
'Did you forget to wrap the messages into an array?'
);
}
const withoutStack = options.withoutStack;
const logAllErrors = options.logAllErrors;
const warningsWithoutComponentStack = [];
const warningsWithComponentStack = [];
const unexpectedWarnings = [];
let lastWarningWithMismatchingFormat = null;
let lastWarningWithExtraComponentStack = null;
// Catch errors thrown by the callback,
// But only rethrow them if all test expectations have been satisfied.
// Otherwise an Error in the callback can mask a failed expectation,
// and result in a test that passes when it shouldn't.
let caughtError;
const isLikelyAComponentStack = message =>
typeof message === 'string' &&
(message.includes('\n in ') || message.includes('\n at '));
const consoleSpy = (format, ...args) => {
// Ignore uncaught errors reported by jsdom
// and React addendums because they're too noisy.
if (
!logAllErrors &&
consoleMethod === 'error' &&
shouldIgnoreConsoleError(format, args)
) {
return;
}
const message = util.format(format, ...args);
const normalizedMessage = normalizeCodeLocInfo(message);
// Remember if the number of %s interpolations
// doesn't match the number of arguments.
// We'll fail the test if it happens.
let argIndex = 0;
format.replace(/%s/g, () => argIndex++);
if (argIndex !== args.length) {
lastWarningWithMismatchingFormat = {
format,
args,
expectedArgCount: argIndex,
};
}
// Protect against accidentally passing a component stack
// to warning() which already injects the component stack.
if (
args.length >= 2 &&
isLikelyAComponentStack(args[args.length - 1]) &&
isLikelyAComponentStack(args[args.length - 2])
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does createMatcherFor() do?
createMatcherFor() is a function in the react codebase, defined in fixtures/legacy-jsx-runtimes/setupTests.js.
Where is createMatcherFor() defined?
createMatcherFor() is defined in fixtures/legacy-jsx-runtimes/setupTests.js at line 57.
What does createMatcherFor() call?
createMatcherFor() calls 2 function(s): normalizeCodeLocInfo, shouldIgnoreConsoleError.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free