{"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,"search_vec":"'1.0.0':80,88 'abil':49 'activ':83 'aid':71 'also':122 'assumpt':23 'automat':51 'ava':113 'case':41,55 'caus':64 'complet':99 'comprehens':124 'consist':26 'current':77 'debug':73 'dedic':119 'defin':19 'definit':129 'develop':17,84,135 'doublecheck':144 'draw':11 'empow':16 'fail':53,68 'featur':44 'flow':127 'framework':110 'function':91 'generat':8,39,146 'great':70 'hold':27 'identifi':56 'includ':123 'indic':82 'input':40,62 'inspir':12 'integr':105 'jasmine/jest':114 'javascript':5,108,137 'larg':35 'librari':6 'mocha':115 'modern':131 'number':36 'offer':103 'packag':75 'plugin':120 'popular':107 'possibl':61 'program':20 'properti':9,21,32,66,141 'quickcheck':14,143 'random':38 'rather':96 'rc.2':81 'releas':89 'report':58 'runner':101 'safe':134 'seamless':104 'shrink':52 'signific':43 'smallest':60 'stabl':87 'subsequ':29 'support':130 'tape':117 'test':10,30,54,94,100,109,138,140,142 'testcheck':145 'testcheck.js':1,2,46 'toward':85 'true':28 'type':128,133 'type-saf':132 'typescript':125,147 'unit':139 'util':95 'version':79 'workflow':136","created_at":"2026-04-19T13:41:36.281898+00:00","updated_at":"2026-04-19T13:41:36.281898+00:00","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","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":"http://leebyron.com/testcheck-js","github":"https://github.com/leebyron/testcheck-js","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/testcheck","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}