DEV Community

shadowtime2000
shadowtime2000

Posted on

Testing With Deno - Framework

Testing With Deno

In this multipart tutorial I will show how to test with Deno.

The Built-in Deno Testing

Deno has it's own built in testing framework

// some_file_test.ts
Deno.test({
    name: "my test",
    fn: (): void => {
        // Do some testing here
    }
});
Enter fullscreen mode Exit fullscreen mode

And you can run these tests with

$ deno test
Enter fullscreen mode Exit fullscreen mode

But What Is Wrong With This?

Well, it is hard to have structure in your tests, like frameworks such as Jest and Mocha allow.

Rhum - The Deno Testing Framework

Rhum is a Deno testing framework created by the deno-drash REST microframework team. Let's take a look at how you use it.

import { Rhum } from "https://deno.land/x/rhum@v1.1.4/mod.ts";

Rhum.testPlan("some_file_test.ts", () => {
    Rhum.testSuite("MyFunction", () => {
        Rhum.testCase("does stuff", () => {
            // Assert some stuff
        });
    });
});
Enter fullscreen mode Exit fullscreen mode

Benefits

The Rhum testing framework allows you to have more complex organization of unit tests.

I will soon by posting a tutorial on assertion libraries.

Top comments (0)