(...args: ItArgs<T>)
| 603 | * `Deno.test()` instead. |
| 604 | */ |
| 605 | export function it<T>(...args: ItArgs<T>) { |
| 606 | if (TestSuiteInternal.runningCount > 0) { |
| 607 | throw new Error( |
| 608 | "Cannot register new test cases after already registered test cases start running", |
| 609 | ); |
| 610 | } |
| 611 | const assertionState = getAssertionState(); |
| 612 | const options = itDefinition(...args); |
| 613 | const { suite } = options; |
| 614 | const testSuite = suite |
| 615 | ? TestSuiteInternal.suites.get(suite.symbol) |
| 616 | : TestSuiteInternal.current; |
| 617 | |
| 618 | if (!TestSuiteInternal.started) TestSuiteInternal.started = true; |
| 619 | if (testSuite) { |
| 620 | TestSuiteInternal.addStep(testSuite, options); |
| 621 | } else { |
| 622 | const { |
| 623 | name, |
| 624 | fn, |
| 625 | ignore, |
| 626 | only, |
| 627 | permissions, |
| 628 | sanitizeExit = globalSanitizersState.sanitizeExit, |
| 629 | sanitizeOps = globalSanitizersState.sanitizeOps, |
| 630 | sanitizeResources = globalSanitizersState.sanitizeResources, |
| 631 | } = options; |
| 632 | const opts: Deno.TestDefinition = { |
| 633 | name, |
| 634 | async fn(t) { |
| 635 | TestSuiteInternal.runningCount++; |
| 636 | try { |
| 637 | await fn.call({} as T, t); |
| 638 | } finally { |
| 639 | TestSuiteInternal.runningCount--; |
| 640 | } |
| 641 | |
| 642 | try { |
| 643 | if (assertionState.checkAssertionErrorState()) { |
| 644 | throw new AssertionError( |
| 645 | "Expected at least one assertion to be called but received none", |
| 646 | ); |
| 647 | } |
| 648 | |
| 649 | if (assertionState.checkAssertionCountSatisfied()) { |
| 650 | throw new AssertionError( |
| 651 | `Expected exactly ${assertionState.assertionCount} ${ |
| 652 | assertionState.assertionCount === 1 ? "assertion" : "assertions" |
| 653 | } to be called, ` + |
| 654 | `but received ${assertionState.assertionTriggeredCount}`, |
| 655 | ); |
| 656 | } |
| 657 | } finally { |
| 658 | assertionState.resetAssertionState(); |
| 659 | } |
| 660 | }, |
| 661 | }; |
| 662 | if (ignore !== undefined) { |
no test coverage detected