ValeriaVG / tiny-jest

Minimalistic zero dependency Jest-like test library to run tests in browser, nodejs or deno
16 stars 1 forks source link
browser deno jest nodejs test testing tiny zero-dependency

Tiny Jest

Minimalistic library to run Jest-like tests in any JS environment: browser, node or even deno. Perfect to run in sandboxes

Features

Limitations

Installation

NPM:

yarn add tiny-jest

or

npm install tiny-jest

CDN:

<script src="https://unpkg.com/tiny-jest/dist/bundle.js"></script>

Deno:

import {
  Test,
  expect,
  prettify,
} from "https://raw.githubusercontent.com/ValeriaVG/tiny-jest/v1.2.1/dist/mod.ts";

const { it, run, title } = new Test("basic");

it("2+2=4", () => {
  expect(2 + 2).toBe(4);
});

run().then(prettify);

Usage

For benchmarks and usage examples see benchmark folder.

const { it, run, title, before, after } = new Test("name-of-your-test");

before(async () => {
  // some setup
});
after(async () => {
  // some cleanup
});

it("toBe", () => {
  expect(2 + 2).toBe(4);
  expect(2 + 2).not.toBe(5);
});

it("toEqual", () => {
  expect(2 + 2).toEqual("4");
  expect(2 + 2).not.toEqual("5");
});

it("toBeTruthy", () => {
  expect(0).toBeFalsy();
  expect(1).not.toBeFalsy();
});

it("toBeFalsy", () => {
  expect(1).toBeTruthy();
});

it("toMatchObject", () => {
  expect({
    fullName: {
      givenName: "John",
      familyName: "Doe",
    },
  }).toMatchObject({
    fullName: {
      givenName: "John",
    },
  });
  expect({
    givenName: "John",
    familyName: "Doe",
  }).not.toMatchObject({
    fullName: {
      givenName: "John",
    },
  });
});

run().then(prettify);