ts-minitest
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

MiniTest (TS)

A simple assertion and testing library with only one dependency - picocolors. Built to be small and easy to include in environments where running a full-fledged test runner may be difficult to set up.

  • Mimics part of the Jest expect() API.
  • Supports both ESM and CommonJS

Screenshot 2023-02-18 165948

Installation

npm install --save-dev ts-minitest

Usage

Anywhere in your code where you want to run tests, import the library and describe your tests. These tests will run immediately, emit any errors to the console.

import { it, describe, expect } from "ts-minitest";

describe("my test suite", () => {
    it("should throw an error if the assertion fails", () => {
        expect(true).toBe(false);
    });
    
    it("should not throw an error as the assertion passes", () => {
        expect(true).toBe(true);
    });
});

Intention

This library was built to be small and easy to include in any environment where you just need to run a few quick tests programmatically. It is not intended to be a full-fledged test runner, and does not have any of the comforts that you would have from a full-fledged test runner like Jest or Vitest.

A good use case would be if you need tests to run in the browser. For example, for running a suite of tests on request by the user or developer.

// local-storage.test.ts
import { it, describe, expect } from "ts-minitest";

describe("local storage", () => {
    it("should have a session ID", () => {
        const sessionId = window.localStorage.getItem("session-id");
        expect(typeof sessionId).toBe("string");
        expect(sessionId.length).not.toBe("");
    });
});

Readme

Keywords

none

Package Sidebar

Install

npm i ts-minitest

Weekly Downloads

15

Version

1.1.0

License

ISC

Unpacked Size

15.6 kB

Total Files

5

Last publish

Collaborators

  • jorgenvatle