test_utils

🦕 Testing library for Deno

Installation

$ deno install https://deno.land/x/test_utils/mod.ts

Example

import { assertEq } from "https://deno.land/x/test_utils/mod.ts";
assertEq(2, 2);                        // Works
assertEq(3, 0, "This will fail");      // Throw error
import { arrayAssert } from "https://deno.land/x/test_utils/mod.ts";
arrayAssert([], []);                 // Works
arrayAssert([], [1]);                // Throw error since mismatched length
arrayAssert([0], [0]);               // Works
import { test } from "https://deno.land/x/test_utils/mod.ts";

function add(x: number, y: number): number {
  return x + y;
}

test(add(1, 2)).toBe(3);             // Works
test(add(1, 2)).instanceOf(Number);  // Works

API

Function

  • assertEq(left, right [, message])
function assertEq<T>(left: T, right: T, message?: string): void

Throws an AssertionError if left is not the same as right

  • assertNeq(left, right [, message])
function assertNeq(left: unknown, right: unknown, message?: string): void

Throws an AssertionError if left is the same as right

  • arrayAssertEq(left, right [, message])
function arrayAssert<T>(left: T[], right: T[], message?: string): void

Throws an AssertionError if left[i] is not the same as right[i]

  • test(fn)
function test<T>(fn): TestResult<T>

Returns a TestResult<T>

Class

  • AssertionError
class AssertionError extends Error

Extension of the Error class

  • TestError
class TestError extends Error

Extension of the Error class

Interface

  • TestResult<T>
interface TestResult<T> {
  toBe: (n: T) => void;
  instaceOf: (n: new () => unknown) => void;
}

License

This project is licensed under the MIT License. Read more here