test.js Unit Test Suite

0.0.4 · abandoned · verified Sun Apr 19

test.js is an extremely lightweight, console API-based unit testing library designed for both Node.js and browser environments. It provides a minimal API for defining test suites and individual tests using simple `[EXPRESSION, EXPECTATION]` arrays. The library aims for simplicity over feature richness, distinguishing itself from more comprehensive testing frameworks. Its latest version, 0.0.4, was released in 2014, indicating that the project is no longer actively maintained. Due to its age, it supports CommonJS modules and global browser scope but lacks modern JavaScript features like ESM, async/await testing, or advanced assertion libraries. Developers seeking a simple, low-overhead solution for basic equality checks in legacy projects might find it useful, but it is not recommended for new projects or environments requiring modern testing paradigms or comprehensive reporting.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define and run basic test suites with test.js in both Node.js and browser environments, including examples of passing and failing assertions.

// quickstart.js
// This example demonstrates basic usage of the test.js library for simple unit tests.
// Run this file with Node.js after 'npm install test-js' or include test.js in an HTML file.

var test = require('test-js'); // For Node.js environments

// Define a test suite named 'Basic Arithmetic Operations'
test.suite('Basic Arithmetic Operations', {
    // A simple test for addition
    'Addition: 1 + 1 should equal 2': [1 + 1, 2],

    // Another addition test, expecting a different result
    'Addition: 5 + 3 should equal 8': [5 + 3, 8],

    // Test for subtraction
    'Subtraction: 10 - 5 should equal 5': [10 - 5, 5],

    // An intentionally failing test to demonstrate failure output
    'Subtraction: 7 - 2 should NOT equal 4 (expected to fail)': [7 - 2, 4], // This will fail

    // Test for multiplication
    'Multiplication: 3 * 4 should equal 12': [3 * 4, 12],

    // Test for division
    'Division: 10 / 2 should equal 5': [10 / 2, 5]
});

// Define another suite for boolean logic
test.suite('Boolean Logic Tests', {
    'True is true': [true, true],
    'False is false': [false, false],
    'NOT true is false': [!true, false],
    'AND operator: true && true is true': [true && true, true],
    'OR operator: false || true is true': [false || true, true]
});

// To run this in Node.js:
// 1. Save as e.g., 'my-tests.js'
// 2. npm install test-js
// 3. node my-tests.js
//
// To run in a browser:
// 1. Download test.js
// 2. <script src="test.js"></script>
// 3. <script src="my-tests.js"></script>
// 4. Open the HTML file in a browser and check the console.

view raw JSON →