( label: string, thrown: Thrown | null, key: string, expected?: string | RegExp, )
| 405 | `${label + printExpected(expected)}\n`; |
| 406 | |
| 407 | const formatReceived = ( |
| 408 | label: string, |
| 409 | thrown: Thrown | null, |
| 410 | key: string, |
| 411 | expected?: string | RegExp, |
| 412 | ) => { |
| 413 | if (thrown === null) { |
| 414 | return ''; |
| 415 | } |
| 416 | |
| 417 | if (key === 'message') { |
| 418 | const message = thrown.message; |
| 419 | |
| 420 | if (typeof expected === 'string') { |
| 421 | const index = message.indexOf(expected); |
| 422 | if (index !== -1) { |
| 423 | return `${ |
| 424 | label + |
| 425 | printReceivedStringContainExpectedSubstring( |
| 426 | message, |
| 427 | index, |
| 428 | expected.length, |
| 429 | ) |
| 430 | }\n`; |
| 431 | } |
| 432 | } else if (expected instanceof RegExp) { |
| 433 | return `${ |
| 434 | label + |
| 435 | printReceivedStringContainExpectedResult( |
| 436 | message, |
| 437 | typeof expected.exec === 'function' ? expected.exec(message) : null, |
| 438 | ) |
| 439 | }\n`; |
| 440 | } |
| 441 | |
| 442 | return `${label + printReceived(message)}\n`; |
| 443 | } |
| 444 | |
| 445 | if (key === 'name') { |
| 446 | return thrown.isError |
| 447 | ? `${label + printReceived(thrown.value.name)}\n` |
| 448 | : ''; |
| 449 | } |
| 450 | |
| 451 | if (key === 'value') { |
| 452 | return thrown.isError ? '' : `${label + printReceived(thrown.value)}\n`; |
| 453 | } |
| 454 | |
| 455 | return ''; |
| 456 | }; |
| 457 | |
| 458 | const formatStack = (thrown: Thrown | null) => { |
| 459 | if (thrown === null || !thrown.isError) { |
no test coverage detected