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
	}
});

And you can run these tests with

$ deno test

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
		});
	});
});

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.

Back | DEV.to

shadowtime2000

If you are looking at this you probably wonder who I am; teenage open source maintainer

shadowtime2000's DEV profile image