{"id":12135,"library":"testcheck","title":"TestCheck.js","description":"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.","status":"active","version":"1.0.0-rc.2","language":"javascript","source_language":"en","source_url":"git://github.com/leebyron/testcheck-js","tags":["javascript","test","unit test","property test","quickcheck","doublecheck","testcheck","generative","typescript"],"install":[{"cmd":"npm install testcheck","lang":"bash","label":"npm"},{"cmd":"yarn add testcheck","lang":"bash","label":"yarn"},{"cmd":"pnpm add testcheck","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"const check = require('testcheck');","symbol":"check","correct":"import { check } from 'testcheck';"},{"note":"An object providing various predefined data generators (e.g., `gen.int`, `gen.string`, `gen.array`). It is a named export from the main package.","wrong":"import * as gen from 'testcheck/gen';","symbol":"gen","correct":"import { gen } from 'testcheck';"},{"note":"Used to encapsulate a predicate function into a testable property. It is available as a named export; do not attempt a default import.","wrong":"import Property from 'testcheck';","symbol":"property","correct":"import { property } from 'testcheck';"},{"note":"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.","wrong":"import { check, gen, property } from 'testcheck';","symbol":"{ check, gen, property } (CommonJS)","correct":"const { check, gen, property } = require('testcheck');"}],"quickstart":{"code":"import { check, gen, property } from 'testcheck';\n\n// Define a property: any integer subtracted from itself should be 0.\n// TestCheck will generate various integer inputs (x) and check this property.\nconst subtractionProperty = property(\n  gen.int, // Generator for an integer input\n  (x: number) => x - x === 0\n);\n\n// Run the property check with default settings\nconst result = check(subtractionProperty);\n\n// Log the outcome. In a real test suite (e.g., Jest, Mocha), you'd use\n// framework-specific assertions based on `result.pass`.\nif (result.pass) {\n  console.log('Property holds true for all generated cases after ' + result.numTests + ' tests.');\n} else {\n  console.error(`Property failed after ${result.numTests} tests.`);\n  console.error(`Failing input (minimal): ${JSON.stringify(result.shrunk.smallest)}`);\n  // Access original failing input: result.fail\n}\n\n// Example with multiple generators and a more complex property\nconst additionCommutativity = property(\n  gen.int, gen.int,\n  (a: number, b: number) => a + b === b + a\n);\n\nconst addResult = check(additionCommutativity);\nif (!addResult.pass) {\n  console.error(`Addition commutativity failed for: ${JSON.stringify(addResult.shrunk.smallest)}`);\n}","lang":"typescript","description":"This quickstart demonstrates how to define and run a basic property test using `gen.int` and `check`, illustrating both success and failure reporting."},"warnings":[{"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.","message":"The `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.","severity":"breaking","affected_versions":"<1.0.0"},{"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.","message":"TestCheck.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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"As 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.","severity":"gotcha","affected_versions":"1.0.0-rc.x"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"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.","error":"TypeError: (0 , testcheck__WEBPACK_IMPORTED_MODULE_0__.check) is not a function"},{"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).","cause":"The `check` function (or `gen`, `property`) was not imported or required correctly into the current JavaScript scope before being used.","error":"ReferenceError: check is not defined"},{"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.","cause":"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.","error":"Property function did not return true"}],"ecosystem":"npm"}