Deno Test Runner

Posted in category Deno on
439 Words ~3 Minute Reading Time • Subscribe to receive updates on Deno
Eric David Smith
Software Engineer / Musician / Entrepreneur
Deno Test Runner by Eric David Smith

Deno is just incredible. I just can't seem to get enough of it. I know I have just barely scratched the surface, but ohhh-mmm-geeee it is just so sick!

Admittedly though, I have been following the project for years. When I tried it when it was first introduced, I didn't have a reason to use Deno. At the time, it was just not working as expected.

Deno Has A Built-In Test Runner!!

Throughout my career, I have used so many testing libraries that it made my head spin. Having something in-the-box makes a lot of sense to me.

You just need to call

Deno.test({
  // your test stuff in here!
});

What are you thoughts on how cool this is?

Let's Test Our Code

First, create a new file. I created a new directory in the root of my project called tests/ and inside of it, I created a file called test1.ts.

Inside of the file we can add the following:

import { assertEquals } from "https://deno.land/std@0.191.0/testing/asserts.ts";

Now that this file has been created, we can start testing for real.

Let's Make Our Tests Fail ❌

It's important for any testing library to make sure the tests pass and fail. The first thing I typically do in a project that requires testing is making them fail.

// Let's fail a test ❌
Deno.test("math test - fails", () => {
  const math = 1 + 2;
  assertEquals<number>(math, 4); // 4 is not 3 - go back and repeat math class!
});

Let's Make Our Tests Pass ✅

It's important for any testing library to make sure the tests pass and fail. The first thing I typically do in a project that requires testing is making them fail.

// Let's pass a test ✅
Deno.test("math test - passes", () => {
  const math = 1 + 2;
  assertEquals<number>(math, 3); // 3 is the correct answer. Profit & Win!
});

Lastly, Run The Deno Tests

All you will need to do is run the following command from the terminal from the root of your project. If you followed along correctly, you should see 2 tests completed with 1 pass and 1 fail.

deno test tests/test1.ts

Deno Documentation on Testing

Thanks for reading. Happy coding!

Supporting My Work

Please consider Buying Me A Coffee. I work hard to bring you my best content and any support would be greatly appreciated. Thank you for your support!

Contact


Eric David Smith
Software Engineer / Musician / Entrepreneur
Deno

Related Blog Posts

Blog Post Tags