Giter Site home page Giter Site logo

valeriavg / tiny-jest Goto Github PK

View Code? Open in Web Editor NEW
16.0 3.0 1.0 103 KB

Minimalistic zero dependency Jest-like test library to run tests in browser, nodejs or deno

TypeScript 48.38% JavaScript 33.44% HTML 18.18%
jest browser deno nodejs test testing zero-dependency tiny

tiny-jest's Introduction

Tiny Jest

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

Features

  • Zero dependency
  • Ultra fast
  • Clean Jest-like api
  • Runs in browser
  • Provides jest-like "expect" library, but can be used with any assert/expect library

Limitations

  • Doesn't include cli-runner
  • Included "expect" library has limited amount of matchers, much less than original Jest expect

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);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.