This module extends Deno's built-in test runner to add setup/teardown hooks

This module extends Deno's built-in test runner to add setup/teardown hooks

This module extends Deno's built-in test runner to add setup/teardown hooks and the ability to organize tests

Test Suite

This module extends Deno's built-in test runner to add setup/teardown hooks and the ability to organize tests.

Features

  • Ability to group tests together into test suites
  • Setup/teardown hooks for test suites(beforeAll, afterAll, beforeEach, afterEach)
  • Tests within a test suite inherit configuration options

Installation

To include this module in a Deno project, you can import directly from the TS files. This module is available in Deno's third part module registry but can also be imported directly from GitHub using raw content URLs.

// Import from Deno's third party module registry
import { TestSuite, test } from "https://deno.land/x/[email protected]/mod.ts";
// Import from GitHub
import { TestSuite, test } "https://raw.githubusercontent.com/udibo/test_suite/v0.5.2/mod.ts";

Usage

Below are some examples of how to use TestSuite and test in tests.

See deno docs for more information.

TestSuite

When you have a set of tests that are related, you can group them together by creating a test suite. A test suite can contain other test suites and tests. All tests within a suite will inherit their options from the suite unless they specifically set them.

The beforeAll and afterAll hook options can be used to do something before and after all the tests in the suite run. If you would like to set values for all tests within the suite, you can create a context interface that defines all the values available to the tests that are defined in the beforeAll function.

The beforeEach and afterEach hook options are similar to beforeAll and afterAll except they are called before and after each individual test.

The example test below can be found in the example directory.

import { TestSuite, test } from "https://deno.land/x/[email protected]/mod.ts";
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { User, getUser, resetUsers } from "./example/user.ts";

interface UserSuiteContext {
  user: User;
}
const userSuite: TestSuite<UserSuiteContext> = new TestSuite({
  name: "user",
  beforeEach(context: UserSuiteContext) {
    context.user = new User("Kyle June");
  },
  afterEach() {
    resetUsers();
  },
});

test(userSuite, "create", () => {
  const user = new User("John Doe");
  assertEquals(user.name, "John Doe");
});

const getUserSuite: TestSuite<UserSuiteContext> = new TestSuite({
  name: "getUser",
  suite: userSuite,
});

test(getUserSuite, "user does not exist", () => {
  assertEquals(getUser("John Doe"), undefined);
});

test(getUserSuite, "user exists", (context: UserSuiteContext) => {
  assertEquals(getUser("Kyle June"), context.user);
});

test(userSuite, "resetUsers", (context: UserSuiteContext) => {
  assertEquals(getUser("Kyle June"), context.user);
  resetUsers();
  assertEquals(getUser("Kyle June"), undefined);
});

If you run the above tests using deno test, you will get the following output. Each test name is prefixed with the suite name.

$ deno test
running 4 tests
test user create ... ok (4ms)
test user getUser user does not exist ... ok (1ms)
test user getUser user exists ... ok (2ms)
test user resetUsers ... ok (2ms)

test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (11ms)

Download Details:

Author: udibo

Source Code: https://github.com/udibo/test_suite

deno nodejs node javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

AEM Querybuilder for JavaScript (Browser, Node, Deno)

Helix Querybuilder .AEM Querybuilder for JavaScript (Browser, Node, Deno)

NKeys for JavaScript - Node.js, Browsers, and Deno

A public-key signature system based on Ed25519 for the NATS ecosystem system for JavaScript. The nkeys.js library works in Deno, Node.js, and the browser!

Javascript module for easily generating mazes,compatible with both Deno and Node

A work-in-progress Javascript maze generator module, compatible with both Deno and Node.

Deno Tutorial for Beginners: Deno vs. Node: Better Than NodeJS?

Deno is released, it’s time to find out if it can prove a worthy competition for Node.js. What is Deno? Why Deno can be considered an alternative to Node? The main differences between Deno and Node. Write a simple Deno app.

What is Deno? The Node.JS Killer? The Deno-minator to Node?

What is Deno? The Node.JS Killer? The Deno-minator to Node? Deno is the new hype and will it be better than node.js? Deno is a secure runtime for JavaScript and TypeScript that is based on the V8 JavaScript engine and the Rust programming language that addresses Node’s shortcomings