Registry / testing / testcheck

testcheck

JSON →
library1.0.0-rc.2jsnpmunverified

TestCheck.js is a JavaScript library for generative property testing, drawing inspiration from QuickCheck. It empowers developers to define program properties or assumptions that should consistently hold true, subsequently testing these properties against a large number of randomly generated input cases. A significant feature of TestCheck.js is its ability to automatically shrink failing test cases, identifying and reporting the smallest possible input that causes a property to fail, which greatly aids in debugging. The package is currently at version 1.0.0-rc.2, indicating active development towards a stable 1.0.0 release. While functioning as a testing utility rather than a complete test runner, it offers seamless integration with popular JavaScript test frameworks such as AVA, Jasmine/Jest, Mocha, and Tape through dedicated plugins. It also includes comprehensive TypeScript and Flow type definitions, supporting modern, type-safe development workflows.

npm install testcheck
INSTALL
IMPORT
SIG · TESTCHECK
T
testcheck
testingjavascriptv1.0.0-rc.2
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

check
✓ import { check } from 'testcheck';
✗ const check = require('testcheck');
The primary function to execute property tests. For ES Modules and TypeScript, use a named import. Using `require` in an ESM context will likely fail.
gen
✓ import { gen } from 'testcheck';
✗ import * as gen from 'testcheck/gen';
An object providing various predefined data generators (e.g., `gen.int`, `gen.string`, `gen.array`). It is a named export from the main package.
property
✓ import { property } from 'testcheck';
✗ import Property from 'testcheck';
Used to encapsulate a predicate function into a testable property. It is available as a named export; do not attempt a default import.
{ check, gen, property } (CommonJS)
✓ const { check, gen, property } = require('testcheck');
✗ import { check, gen, property } from 'testcheck';
For CommonJS environments, destructure named exports directly from the `require` call. Mixing ES Modules import syntax with CommonJS `require` in the same file can lead to unexpected behavior.

This quickstart demonstrates how to define and run a basic property test using `gen.int` and `check`, illustrating both success and failure reporting.

import { check, gen, property } from 'testcheck'; // Define a property: any integer subtracted from itself should be 0. // TestCheck will generate various integer inputs (x) and check this property. const subtractionProperty = property( gen.int, // Generator for an integer input (x: number) => x - x === 0 ); // Run the property check with default settings const result = check(subtractionProperty); // Log the outcome. In a real test suite (e.g., Jest, Mocha), you'd use // framework-specific assertions based on `result.pass`. if (result.pass) { console.log('Property holds true for all generated cases after ' + result.numTests + ' tests.'); } else { console.error(`Property failed after ${result.numTests} tests.`); console.error(`Failing input (minimal): ${JSON.stringify(result.shrunk.smallest)}`); // Access original failing input: result.fail } // Example with multiple generators and a more complex property const additionCommutativity = property( gen.int, gen.int, (a: number, b: number) => a + b === b + a ); const addResult = check(additionCommutativity); if (!addResult.pass) { console.error(`Addition commutativity failed for: ${JSON.stringify(addResult.shrunk.smallest)}`); }
Debug
Known issues
breakingThe `1.0.0-rc.0` release introduced significant changes and new features, implying potential breaking API changes for users upgrading from pre-1.0 (e.g., 0.x) versions. A full report was promised for the final `1.0.0` release.
fix
Consult the official API documentation (http://leebyron.com/testcheck-js/api) and the Walkthrough Guide (http://leebyron.com/testcheck-js/guide) for updated API usage and migration details.
affects: <1.0.0
gotchaTestCheck.js is a property testing *utility* and does not include a test runner. It must be integrated with an existing test framework (like AVA, Jasmine/Jest, Mocha, or Tape) or its `check` function called explicitly. It will not automatically discover and run tests.
fix
If using a test framework, install and configure the relevant `testcheck` integration package (e.g., `ava-check`, `jasmine-check`). Otherwise, invoke `check()` directly within your testing environment.
affects: >=0.1.0
gotchaAs a release candidate (`1.0.0-rc.2`), the API is generally stable but may still undergo minor adjustments or refinements before the final `1.0.0` release. Users should be aware of potential, albeit small, changes.
fix
Monitor the official GitHub repository and documentation for updates leading up to the final `1.0.0` release. Ensure your test suite has adequate coverage to detect any unexpected behavior from minor API shifts.
affects: 1.0.0-rc.x
Errors
Common errors & fixes
TypeError: (0 , testcheck__WEBPACK_IMPORTED_MODULE_0__.check) is not a function
This typically occurs when mixing CommonJS `require` with ES Modules `import` syntax, or when a bundler incorrectly transpiles the module, or if `check` is attempted to be used as a default import when it's a named export.
fix
Ensure consistent import style: use `import { check, gen, property } from 'testcheck';` for ES Modules/TypeScript environments, or `const { check, gen, property } = require('testcheck');` for CommonJS environments.
ReferenceError: check is not defined
The `check` function (or `gen`, `property`) was not imported or required correctly into the current JavaScript scope before being used.
fix
Add the necessary import statement at the top of your file: `import { check, gen, property } from 'testcheck';` (for ESM/TS) or `const { check, gen, property } = require('testcheck');` (for CommonJS).
Property function did not return true
This is TestCheck.js reporting a test failure. The property function provided returned `false` (or threw an error) for one or more generated test cases. This indicates either a bug in the code under test or an incorrect/flawed property definition.
fix
Examine the `result.shrunk.smallest` output from the `check` function to identify the minimal failing input. Debug your property function and/or the application code it tests to resolve the discrepancy.
Upgrade
Version history
1.0.0-rc.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
Resources
testcheck — npm install testcheck · libregistry