Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/deno/cli/tsc/dts/lib.deno.ns.d.ts>Deno.TestContext

A modern runtime for JavaScript and TypeScript.
Go to Latest
interface Deno.TestContext
import { type Deno } from "https://deno.land/x/deno@v1.28.3/cli/tsc/dts/lib.deno.ns.d.ts";
const { TestContext } = Deno;

Context that is passed to a testing function, which can be used to either gain information about the current test, or register additional test steps within the current test.

Properties

name: string

The current test name.

origin: string

The string URL of the current test.

optional
parent: TestContext

If the current test is a step of another test, the parent test context will be set here.

Methods

step(definition: TestStepDefinition): Promise<boolean>

Run a sub step of the parent test or step. Returns a promise that resolves to a boolean signifying if the step completed successfully.

The returned promise never rejects unless the arguments are invalid.

If the test was ignored the promise returns false.

Deno.test({
  name: "a parent test",
  async fn(t) {
    console.log("before the step");
    await t.step({
      name: "step 1",
      fn(t) {
        console.log("current step:", t.name);
      }
    });
    console.log("after the step");
  }
});
step(name: string, fn: (t: TestContext) => void | Promise<void>): Promise<boolean>

Run a sub step of the parent test or step. Returns a promise that resolves to a boolean signifying if the step completed successfully.

The returned promise never rejects unless the arguments are invalid.

If the test was ignored the promise returns false.

Deno.test(
  "a parent test",
  async (t) => {
    console.log("before the step");
    await t.step(
      "step 1",
      (t) => {
        console.log("current step:", t.name);
      }
    );
    console.log("after the step");
  }
);