ts-minitest
v1.1.0
Published
> A simple assertion and testing library with only one dependency - [`picocolors`](https://www.npmjs.com/package/picocolors). > Built to be small and easy to include in environments where running a full-fledged test runner may be difficult > to set up.
Downloads
441
Readme
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
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("");
});
});