* Handles more complex objects ( such as objects with circular references. * maps and sets etc )
(
val: unknown,
config: PrettyFormatConfig,
indentation: string,
depth: number,
refs: unknown[]
)
| 180 | * maps and sets etc ) |
| 181 | */ |
| 182 | static printComplexValue( |
| 183 | val: unknown, |
| 184 | config: PrettyFormatConfig, |
| 185 | indentation: string, |
| 186 | depth: number, |
| 187 | refs: unknown[] |
| 188 | ): string { |
| 189 | if (refs.includes(val)) { |
| 190 | return '[Circular]'; |
| 191 | } |
| 192 | refs = [...refs]; |
| 193 | refs.push(val); |
| 194 | |
| 195 | const hitMaxDepth = ++depth > config.maxDepth; |
| 196 | const min = config.min; |
| 197 | |
| 198 | const arrayTypeName = PrettyFormat.tryGetIterableType(val); |
| 199 | if (arrayTypeName) { |
| 200 | return hitMaxDepth |
| 201 | ? `[${arrayTypeName}]` |
| 202 | : `${ |
| 203 | min || arrayTypeName.startsWith('_') ? '' : `${arrayTypeName} ` |
| 204 | }[${PrettyFormat.printIterableValues(TestPlatform.typedArrayAsUnknownIterable(val), config, indentation, depth, refs, PrettyFormat.printer)}]`; |
| 205 | } |
| 206 | |
| 207 | if (val instanceof Map) { |
| 208 | return hitMaxDepth |
| 209 | ? '[Map]' |
| 210 | : `Map {${PrettyFormat.printIteratorEntries(TestPlatform.mapAsUnknownIterable(val), config, indentation, depth, refs, PrettyFormat.printer, ' => ')}}`; |
| 211 | } |
| 212 | if (val instanceof Set) { |
| 213 | return hitMaxDepth |
| 214 | ? '[Set]' |
| 215 | : `Set {${PrettyFormat.printIterableValues(TestPlatform.setAsUnknownIterable(val), config, indentation, depth, refs, PrettyFormat.printer)}}`; |
| 216 | } |
| 217 | |
| 218 | // Avoid failure to serialize global window object in jsdom test environment. |
| 219 | // For example, not even relevant if window is prop of React element. |
| 220 | const constructorName = TestPlatform.getConstructorName(val); |
| 221 | return hitMaxDepth |
| 222 | ? `[${constructorName}]` |
| 223 | : `${ |
| 224 | min ? '' : !config.printBasicPrototype && constructorName === 'Object' ? '' : `${constructorName} ` |
| 225 | }{${PrettyFormat._printObjectProperties(val as object, config, indentation, depth, refs)}}`; |
| 226 | } |
| 227 | |
| 228 | private static _printObjectProperties( |
| 229 | val: object, |
no test coverage detected