{"id":14968,"library":"test-js","title":"test.js Unit Test Suite","description":"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.","status":"abandoned","version":"0.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/websperts/test.js","tags":["javascript","test","unit"],"install":[{"cmd":"npm install test-js","lang":"bash","label":"npm"},{"cmd":"yarn add test-js","lang":"bash","label":"yarn"},{"cmd":"pnpm add test-js","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only for Node.js environments. ES Modules are not supported.","wrong":"import test from 'test-js';","symbol":"test","correct":"var test = require('test-js');"},{"note":"The `test` object is typically used directly from its global or module-imported scope.","wrong":"const suite = test.suite; suite('My Suite', { /* tests */ });","symbol":"test.suite","correct":"test.suite('My Suite', { /* tests */ });"},{"note":"In browser environments, `test` is exposed as a global variable after the script is loaded. It does not support ES Module imports in the browser.","wrong":"import { test } from './test.js';","symbol":"test (global)","correct":"<script src=\"test.js\"></script>\n<script>\ntest.suite('My Suite', { /* tests */ });\n</script>"}],"quickstart":{"code":"// quickstart.js\n// This example demonstrates basic usage of the test.js library for simple unit tests.\n// Run this file with Node.js after 'npm install test-js' or include test.js in an HTML file.\n\nvar test = require('test-js'); // For Node.js environments\n\n// Define a test suite named 'Basic Arithmetic Operations'\ntest.suite('Basic Arithmetic Operations', {\n    // A simple test for addition\n    'Addition: 1 + 1 should equal 2': [1 + 1, 2],\n\n    // Another addition test, expecting a different result\n    'Addition: 5 + 3 should equal 8': [5 + 3, 8],\n\n    // Test for subtraction\n    'Subtraction: 10 - 5 should equal 5': [10 - 5, 5],\n\n    // An intentionally failing test to demonstrate failure output\n    'Subtraction: 7 - 2 should NOT equal 4 (expected to fail)': [7 - 2, 4], // This will fail\n\n    // Test for multiplication\n    'Multiplication: 3 * 4 should equal 12': [3 * 4, 12],\n\n    // Test for division\n    'Division: 10 / 2 should equal 5': [10 / 2, 5]\n});\n\n// Define another suite for boolean logic\ntest.suite('Boolean Logic Tests', {\n    'True is true': [true, true],\n    'False is false': [false, false],\n    'NOT true is false': [!true, false],\n    'AND operator: true && true is true': [true && true, true],\n    'OR operator: false || true is true': [false || true, true]\n});\n\n// To run this in Node.js:\n// 1. Save as e.g., 'my-tests.js'\n// 2. npm install test-js\n// 3. node my-tests.js\n//\n// To run in a browser:\n// 1. Download test.js\n// 2. <script src=\"test.js\"></script>\n// 3. <script src=\"my-tests.js\"></script>\n// 4. Open the HTML file in a browser and check the console.","lang":"javascript","description":"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."},"warnings":[{"fix":"Migrate to an actively maintained testing framework like Jest, Mocha, Vitest, or QUnit for modern projects.","message":"Project is abandoned. The last release (0.0.4) was in 2014, and there is no active development or maintenance. Users should not expect bug fixes, security updates, or new features.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"Consider modern alternatives like Jest, Mocha, or Vitest for projects using ES Modules or asynchronous code.","message":"No support for modern JavaScript features. test.js predates ES Modules, async/await, and modern assertion libraries, leading to verbose or impossible testing patterns for contemporary codebases.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"For more robust testing, integrate a dedicated assertion library or switch to a framework with built-in rich assertions.","message":"Limited assertion capabilities. The framework only supports simple equality checks with [EXPRESSION, EXPECTATION] pairs, lacking advanced assertions (e.g., toContain, toMatchObject, toThrow) or mock/spy functionality.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure 'test.js' is loaded via a script tag before calling any 'test' methods in the browser. Place your test script after the library script.","cause":"Attempting to use 'test' in a browser environment without including the <script src=\"test.js\"></script> tag, or before the script has fully loaded.","error":"ReferenceError: test is not defined"},{"fix":"In a Node.js CommonJS environment, ensure 'var test = require('test-js');' is at the top of your file. In a browser, use the global 'test' object after loading the script via <script> tag. This library does not support ES Modules.","cause":"Attempting to use CommonJS 'require' in a browser environment, an ES Module context, or without a Node.js-like environment.","error":"ReferenceError: require is not defined"},{"fix":"Verify the correct import/script loading method for your environment (CommonJS 'require' for Node.js, <script> tag for browser). Check for conflicting global variables if in a browser environment.","cause":"The 'test' object was not correctly loaded, or a different global variable named 'test' is overshadowing the library's export.","error":"TypeError: test.suite is not a function"}],"ecosystem":"npm"}