Socket
Book a DemoInstallSign in
Socket

@star-unit/js

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@star-unit/js

> A lightweight tool for instant JavaScript unit testing.

latest
npmnpm
Version
1.2.4
Version published
Maintainers
1
Created
Source

@star-unit/js

A lightweight tool for instant JavaScript unit testing.

๐Ÿ“ฆ Installation

npm install @star-unit/js

๐Ÿš€ Quick Start

Initialize configuration:

npx suj init

Run tests:

npx suj test

Note: After installation, the CLI is available via the suj command.

โœจ Features

  • Easy-to-use unit testing syntax (describe, test, expect).
  • Rich set of matchers, including .not negations.
  • Lightweight and fast.
  • Supports both frontend and backend JavaScript projects.

๐Ÿ”ฅ CLI Commands

init

Initialize the configuration required by this tool.

Options:

  • -r, --root <root> โ€” Path to the root directory (default: "./").
  • -e, --ext <root> โ€” Test file extension (default: "test.js").

test

Run unit tests.

Options:

  • None.

๐Ÿ› ๏ธ API Reference

describe(description, fn)

Groups related tests together.

describe("Math operations", () => {
  // tests here
});

test(description, fn)

Defines a single unit test.

test("adds numbers correctly", () => {
  const result = 1 + 2;
  expect(result).toBe(3);
});

expect(actual)

Starts an assertion chain for a test result.

expect(4).toBe(4);
expect(4).not.toBe(5);

You can chain .not to invert the matcher logic.

๐ŸŽฏ Matchers

Matchers are used to assert specific conditions. Each matcher has a .not version that inverts its logic.

MatcherDescription.not Version
.toBe(expected)Value is exactly equal (===)Value is not exactly equal
.toEqual(expected)Values are deeply equalValues are not deeply equal
.toThrow(expected?)Function throws errorFunction does not throw
.toBeGreaterThan(expected)Greater than comparisonNot greater than
.toBeLessThan(expected)Less than comparisonNot less than
.toBeNull()Value is nullValue is not null
.toBeTruthy()Value is truthy (!!value === true)Value is not truthy

๐Ÿงช Example

const { describe, test, expect } = require("@star-unit/js");

describe("Array methods", () => {
  test("push adds an item", () => {
    const arr = [];
    arr.push(1);
    expect(arr.length).toBe(1);
    expect(arr[0]).toBe(1);
  });

  test("pop removes the last item", () => {
    const arr = [1, 2, 3];
    const last = arr.pop();
    expect(last).toBe(3);
    expect(arr.length).toBe(2);
  });

  test("pop should not add elements", () => {
    const arr = [1, 2, 3];
    arr.pop();
    expect(arr.length).not.toBe(3);
  });
});

๐Ÿ“œ License

ISC License.

FAQs

Package last updated on 16 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.