Generates an ItDefinition from ItArgs.
(...args: ItArgs<T>)
| 472 | |
| 473 | /** Generates an ItDefinition from ItArgs. */ |
| 474 | function itDefinition<T>(...args: ItArgs<T>): ItDefinition<T> { |
| 475 | let [ |
| 476 | suiteOptionsOrNameOrFn, |
| 477 | optionsOrNameOrFn, |
| 478 | optionsOrFn, |
| 479 | fn, |
| 480 | ] = args; |
| 481 | let suite: TestSuite<T> | undefined = undefined; |
| 482 | let name: string; |
| 483 | let options: |
| 484 | | ItDefinition<T> |
| 485 | | Omit<ItDefinition<T>, "fn"> |
| 486 | | Omit<ItDefinition<T>, "name"> |
| 487 | | Omit<ItDefinition<T>, "fn" | "name">; |
| 488 | if ( |
| 489 | typeof suiteOptionsOrNameOrFn === "object" && |
| 490 | typeof (suiteOptionsOrNameOrFn as TestSuite<T>).symbol === "symbol" |
| 491 | ) { |
| 492 | suite = suiteOptionsOrNameOrFn as TestSuite<T>; |
| 493 | } else { |
| 494 | fn = optionsOrFn as typeof fn; |
| 495 | optionsOrFn = optionsOrNameOrFn as typeof optionsOrFn; |
| 496 | optionsOrNameOrFn = suiteOptionsOrNameOrFn as typeof optionsOrNameOrFn; |
| 497 | } |
| 498 | if (typeof optionsOrNameOrFn === "string") { |
| 499 | name = optionsOrNameOrFn; |
| 500 | if (typeof optionsOrFn === "function") { |
| 501 | fn = optionsOrFn; |
| 502 | options = {}; |
| 503 | } else { |
| 504 | options = optionsOrFn!; |
| 505 | if (!fn) fn = (options as Omit<ItDefinition<T>, "name">).fn; |
| 506 | } |
| 507 | } else if (typeof optionsOrNameOrFn === "function") { |
| 508 | fn = optionsOrNameOrFn; |
| 509 | name = fn.name; |
| 510 | options = {}; |
| 511 | } else { |
| 512 | options = optionsOrNameOrFn!; |
| 513 | if (typeof optionsOrFn === "function") { |
| 514 | fn = optionsOrFn; |
| 515 | } else { |
| 516 | fn = (options as ItDefinition<T>).fn; |
| 517 | } |
| 518 | name = (options as ItDefinition<T>).name ?? fn.name; |
| 519 | } |
| 520 | |
| 521 | return { |
| 522 | ...(suite !== undefined ? { suite } : {}), |
| 523 | ...options, |
| 524 | name, |
| 525 | fn, |
| 526 | }; |
| 527 | } |
| 528 | |
| 529 | /** Registers an individual test case. */ |
| 530 | // deno-lint-ignore deno-style-guide/naming-convention |