liveBook · Manning

JSCheck

As explained in Functional Programming in JavaScript

A JavaScript library for property-based testing that generates random test cases from declared specifications.

JSCheck is a JavaScript library for property-based testing. You declare a function property, provide input generators, and let the library run many randomized cases, including abnormal edge cases that manual tests may miss. section 6.4

A JSCheck test typically combines these parts:

  • A named property test describes the behavior being checked. section 6.4

Testing an average-grade property

JSC.test('Compute Average Grade', function (verdict, grades, grade) { return verdict(computeAverageGrade(grades) === grade); }, [JSC.array(JSC.integer(20), JSC.number(90, 100)), 'A'], function (grades, grade) { return 'Testing for an ' + grade + ' on grades: ' + grades; }); This generates 100 grade arrays in the shown run and reports 100 passing cases.

Custom specifiers extend the input vocabulary. An SSN generator can combine three integer generators and join their results with dashes, allowing the same property-testing workflow to exercise structured strings.

How Functional Programming in JavaScript covers it

How deep it goes
Explains generated inputs, verdicts, reports, QUnit callbacks, and custom specifiers through working JavaScript examples.
Examples
Demonstrates average-grade arrays, generated pass reports, SSN strings, custom generators, and invalid-input failures.
What it assumes
Assumes unit-testing experience and targets pure, referentially transparent functions.
What you can do after
Apply it via JSCheck to declare properties, generate randomized cases, inspect reports, and test structured inputs.
How it connects
Connects property-based testing with pure functions, referential transparency, QuickCheck, QUnit, and unit testing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in JavaScript. The section links point to the parts of the book it draws on.