Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/deno/cli/js/lib.deno.ns.d.ts>Deno.test

A modern runtime for JavaScript and TypeScript.
Go to Latest
function Deno.test
import { Deno } from "https://deno.land/x/deno@v1.0.0/cli/js/lib.deno.ns.d.ts";
const { test } = Deno;

Register a test which will be run when deno test is used on the command line and the containing module looks like a test module. fn can be async if required.

     import {assert, fail, assertEquals} from "https://deno.land/std/testing/asserts.ts";

     Deno.test({
       name: "example test",
       fn(): void {
         assertEquals("world", "world");
       },
     });

     Deno.test({
       name: "example ignored test",
       ignore: Deno.build.os === "windows"
       fn(): void {
         // This test is ignored only on Windows machines
       },
     });

     Deno.test({
       name: "example async test",
       async fn() {
         const decoder = new TextDecoder("utf-8");
         const data = await Deno.readFile("hello_world.txt");
         assertEquals(decoder.decode(data), "Hello world")
       }
     });

Register a test which will be run when deno test is used on the command line and the containing module looks like a test module. fn can be async if required.

   import {assert, fail, assertEquals} from "https://deno.land/std/testing/asserts.ts";

   Deno.test("My test description", ():void => {
     assertEquals("hello", "hello");
   });

   Deno.test("My async test description", async ():Promise<void> => {
     const decoder = new TextDecoder("utf-8");
     const data = await Deno.readFile("hello_world.txt");
     assertEquals(decoder.decode(data), "Hello world")
   });

Parameters

name: string
fn: () => void | Promise<void>