in packages/pretty-format/src/index.ts [203:298]
function printComplexValue(
val: any,
config: Config,
indentation: string,
depth: number,
refs: Refs,
hasCalledToJSON?: boolean,
): string {
if (refs.indexOf(val) !== -1) {
return '[Circular]';
}
refs = refs.slice();
refs.push(val);
const hitMaxDepth = ++depth > config.maxDepth;
const min = config.min;
if (
config.callToJSON &&
!hitMaxDepth &&
val.toJSON &&
typeof val.toJSON === 'function' &&
!hasCalledToJSON
) {
return printer(val.toJSON(), config, indentation, depth, refs, true);
}
const toStringed = toString.call(val);
if (toStringed === '[object Arguments]') {
return hitMaxDepth
? '[Arguments]'
: `${min ? '' : 'Arguments '}[${printListItems(
val,
config,
indentation,
depth,
refs,
printer,
)}]`;
}
if (isToStringedArrayType(toStringed)) {
return hitMaxDepth
? `[${val.constructor.name}]`
: `${
min
? ''
: !config.printBasicPrototype && val.constructor.name === 'Array'
? ''
: `${val.constructor.name} `
}[${printListItems(val, config, indentation, depth, refs, printer)}]`;
}
if (toStringed === '[object Map]') {
return hitMaxDepth
? '[Map]'
: `Map {${printIteratorEntries(
val.entries(),
config,
indentation,
depth,
refs,
printer,
' => ',
)}}`;
}
if (toStringed === '[object Set]') {
return hitMaxDepth
? '[Set]'
: `Set {${printIteratorValues(
val.values(),
config,
indentation,
depth,
refs,
printer,
)}}`;
}
// Avoid failure to serialize global window object in jsdom test environment.
// For example, not even relevant if window is prop of React element.
return hitMaxDepth || isWindow(val)
? `[${getConstructorName(val)}]`
: `${
min
? ''
: !config.printBasicPrototype && getConstructorName(val) === 'Object'
? ''
: `${getConstructorName(val)} `
}{${printObjectProperties(
val,
config,
indentation,
depth,
refs,
printer,
)}}`;
}