MCPcopy
hub / github.com/callstack/react-native-testing-library / validateOptions

Function validateOptions

src/helpers/validate-options.ts:12–31  ·  view source on GitHub ↗
(
  functionName: string,
  restOptions: Record<string, unknown>,
  // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
  callsite: Function,
)

Source from the content-addressed store, hash-verified

10 * @param callsite - The function where the validation is called from (e.g., render, renderHook)
11 */
12export function validateOptions(
13 functionName: string,
14 restOptions: Record<string, unknown>,
15 // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
16 callsite: Function,
17): void {
18 const unknownKeys = Object.keys(restOptions);
19 if (unknownKeys.length > 0) {
20 // Pass the callsite function (e.g., render) to remove it from stack
21 // This leaves only where the user called the function from (e.g., test file)
22 const stackTraceError = new ErrorWithStack('STACK_TRACE_ERROR', callsite);
23 const stackLines = stackTraceError.stack ? stackTraceError.stack.split('\n') : [];
24 // Skip the first line (Error: STACK_TRACE_ERROR) to show the actual call sites
25 // The remaining lines show where the user called the function from
26 const stackTrace = stackLines.length > 1 ? `\n\n${stackLines.slice(1).join('\n')}` : '';
27 logger.warn(
28 `Unknown option(s) passed to ${functionName}: ${unknownKeys.join(', ')}${stackTrace}`,
29 );
30 }
31}

Callers 7

renderFunction · 0.90
configureFunction · 0.90
renderHookFunction · 0.90
testFunctionWithCallFunction · 0.90
renderFunction · 0.90
createConfigFunction · 0.90

Calls

no outgoing calls

Tested by 2

testFunctionWithCallFunction · 0.72
renderFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…