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.
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?
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.
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!
});
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 ✅
.(, {
math = + ;
assertEquals<>(math, );
});
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
Thanks for reading. Happy coding!
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!