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

Function it

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

Source from the content-addressed store, hash-verified

564 * @param args The test case
565 */
566export function it<T>(...args: ItArgs<T>) {
567 if (TestSuiteInternal.runningCount > 0) {
568 throw new Error(
569 "Cannot register new test cases after already registered test cases start running",
570 );
571 }
572 const assertionState = getAssertionState();
573 const options = itDefinition(...args);
574 const { suite } = options;
575 const testSuite = suite
576 ? TestSuiteInternal.suites.get(suite.symbol)
577 : TestSuiteInternal.current;
578
579 if (!TestSuiteInternal.started) TestSuiteInternal.started = true;
580 if (testSuite) {
581 TestSuiteInternal.addStep(testSuite, options);
582 } else {
583 const {
584 name,
585 fn,
586 ignore,
587 only,
588 permissions,
589 sanitizeExit = globalSanitizersState.sanitizeExit,
590 sanitizeOps = globalSanitizersState.sanitizeOps,
591 sanitizeResources = globalSanitizersState.sanitizeResources,
592 } = options;
593 const opts: Deno.TestDefinition = {
594 name,
595 async fn(t) {
596 TestSuiteInternal.runningCount++;
597 try {
598 await fn.call({} as T, t);
599 } finally {
600 TestSuiteInternal.runningCount--;
601 }
602
603 try {
604 if (assertionState.checkAssertionErrorState()) {
605 throw new AssertionError(
606 "Expected at least one assertion to be called but received none",
607 );
608 }
609
610 if (assertionState.checkAssertionCountSatisfied()) {
611 throw new AssertionError(
612 `Expected exactly ${assertionState.assertionCount} ${
613 assertionState.assertionCount === 1 ? "assertion" : "assertions"
614 } to be called, ` +
615 `but received ${assertionState.assertionTriggeredCount}`,
616 );
617 }
618 } finally {
619 assertionState.resetAssertionState();
620 }
621 },
622 };
623 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