MCPcopy Create free account
hub / github.com/denoland/std / it

Function it

testing/bdd.ts:605–682  ·  view source on GitHub ↗
(...args: ItArgs<T>)

Source from the content-addressed store, hash-verified

603 * `Deno.test()` instead.
604 */
605export 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) {

Callers 7

bdd_test.tsFile · 0.90
bdd.tsFile · 0.70
testFunction · 0.70

Calls 5

getAssertionStateFunction · 0.85
itDefinitionFunction · 0.85
addStepMethod · 0.80
registerTestMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected