(
matcherName: string,
received = 'received',
expected = 'expected',
options: MatcherHintOptions = {},
)
| 522 | // New format: rejects/resolves, not, and matcher name have black color |
| 523 | // Old format: matcher name has dim color |
| 524 | export const matcherHint = ( |
| 525 | matcherName: string, |
| 526 | received = 'received', |
| 527 | expected = 'expected', |
| 528 | options: MatcherHintOptions = {}, |
| 529 | ): string => { |
| 530 | const { |
| 531 | comment = '', |
| 532 | expectedColor = EXPECTED_COLOR, |
| 533 | isDirectExpectCall = false, // seems redundant with received === '' |
| 534 | isNot = false, |
| 535 | promise = '', |
| 536 | receivedColor = RECEIVED_COLOR, |
| 537 | secondArgument = '', |
| 538 | secondArgumentColor = EXPECTED_COLOR, |
| 539 | } = options; |
| 540 | let hint = ''; |
| 541 | let dimString = 'expect'; // concatenate adjacent dim substrings |
| 542 | |
| 543 | if (!isDirectExpectCall && received !== '') { |
| 544 | hint += DIM_COLOR(`${dimString}(`) + receivedColor(received); |
| 545 | dimString = ')'; |
| 546 | } |
| 547 | |
| 548 | if (promise !== '') { |
| 549 | hint += DIM_COLOR(`${dimString}.`) + promise; |
| 550 | dimString = ''; |
| 551 | } |
| 552 | |
| 553 | if (isNot) { |
| 554 | hint += `${DIM_COLOR(`${dimString}.`)}not`; |
| 555 | dimString = ''; |
| 556 | } |
| 557 | |
| 558 | if (matcherName.includes('.')) { |
| 559 | // Old format: for backward compatibility, |
| 560 | // especially without promise or isNot options |
| 561 | dimString += matcherName; |
| 562 | } else { |
| 563 | // New format: omit period from matcherName arg |
| 564 | hint += DIM_COLOR(`${dimString}.`) + matcherName; |
| 565 | dimString = ''; |
| 566 | } |
| 567 | |
| 568 | if (expected === '') { |
| 569 | dimString += '()'; |
| 570 | } else { |
| 571 | hint += DIM_COLOR(`${dimString}(`) + expectedColor(expected); |
| 572 | if (secondArgument) { |
| 573 | hint += DIM_COLOR(', ') + secondArgumentColor(secondArgument); |
| 574 | } |
| 575 | dimString = ')'; |
| 576 | } |
| 577 | |
| 578 | if (comment !== '') { |
| 579 | dimString += ` // ${comment}`; |
| 580 | } |
| 581 |
no test coverage detected