Generates an ItDefinition from ItArgs.
(...args: ItArgs<T>)
| 503 | |
| 504 | /** Generates an ItDefinition from ItArgs. */ |
| 505 | function itDefinition<T>(...args: ItArgs<T>): ItDefinition<T> { |
| 506 | let [ |
| 507 | suiteOptionsOrNameOrFn, |
| 508 | optionsOrNameOrFn, |
| 509 | optionsOrFn, |
| 510 | fn, |
| 511 | ] = args; |
| 512 | let suite: TestSuite<T> | undefined = undefined; |
| 513 | let name: string; |
| 514 | let options: |
| 515 | | ItDefinition<T> |
| 516 | | Omit<ItDefinition<T>, "fn"> |
| 517 | | Omit<ItDefinition<T>, "name"> |
| 518 | | Omit<ItDefinition<T>, "fn" | "name">; |
| 519 | if ( |
| 520 | typeof suiteOptionsOrNameOrFn === "object" && |
| 521 | typeof (suiteOptionsOrNameOrFn as TestSuite<T>).symbol === "symbol" |
| 522 | ) { |
| 523 | suite = suiteOptionsOrNameOrFn as TestSuite<T>; |
| 524 | } else { |
| 525 | fn = optionsOrFn as typeof fn; |
| 526 | optionsOrFn = optionsOrNameOrFn as typeof optionsOrFn; |
| 527 | optionsOrNameOrFn = suiteOptionsOrNameOrFn as typeof optionsOrNameOrFn; |
| 528 | } |
| 529 | if (typeof optionsOrNameOrFn === "string") { |
| 530 | name = optionsOrNameOrFn; |
| 531 | if (typeof optionsOrFn === "function") { |
| 532 | fn = optionsOrFn; |
| 533 | options = {}; |
| 534 | } else { |
| 535 | options = optionsOrFn!; |
| 536 | if (!fn) fn = (options as Omit<ItDefinition<T>, "name">).fn; |
| 537 | } |
| 538 | } else if (typeof optionsOrNameOrFn === "function") { |
| 539 | fn = optionsOrNameOrFn; |
| 540 | name = fn.name; |
| 541 | options = {}; |
| 542 | } else { |
| 543 | options = optionsOrNameOrFn!; |
| 544 | if (typeof optionsOrFn === "function") { |
| 545 | fn = optionsOrFn; |
| 546 | } else { |
| 547 | fn = (options as ItDefinition<T>).fn; |
| 548 | } |
| 549 | name = (options as ItDefinition<T>).name ?? fn.name; |
| 550 | } |
| 551 | |
| 552 | return { |
| 553 | ...(suite !== undefined ? { suite } : {}), |
| 554 | ...options, |
| 555 | name, |
| 556 | fn, |
| 557 | }; |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * Registers an individual test case. |