liveBook · Manning

QUnit

As explained in Functional Programming in JavaScript

A JavaScript unit testing framework for writing and running tests in the browser or other environments.

QUnit is a JavaScript unit-testing framework for checking whether functions produce expected results. Tests live separately from application code and import the functions under test. section 6.1 section 6.0

A basic test names a case, calls a function, and uses an assertion to compare the result with the expected value. This isolates small units of behavior and supports repeatable tests. section 6.1

Testing a function

QUnit.test('Test Find Person', function(assert) { const ssn = '444-44-4444'; const person = findPerson(ssn); assert.equal(person.ssn, ssn); }); section 6.1

QUnit is especially useful for functional code because predictable, modular functions are easier to test independently. Side effects and mutations make imperative code harder to test consistently. section 6.1 section 6.0

QUnit.test('Test Find Person', function(assert) {
  const ssn = '444-44-4444';
  const p = findPerson(ssn);
  assert.equal(p.ssn, ssn);
});

Use the compact listing to inspect the structure of a QUnit test, including its test name, assertion object, function call, and equality check. section 6.1

QUnit can also work with Blanket.js to display statement-coverage results. Coverage reveals which code paths tests execute, although coverage differs between imperative and functional implementations. section 6.5

How Functional Programming in JavaScript covers it

How deep it goes
Demonstrates test structure and assertions, but defers setup details and broader testing-library configuration.
Examples
Uses findPerson and showStudent tests with valid and null inputs, plus QUnit/Blanket coverage reports.
What it assumes
Assumes familiarity with unit testing and JavaScript functions while leaving library setup to external instructions.
What you can do after
Apply it via QUnit.test to verify JavaScript functions and inspect executed statements with Blanket.js.
How it connects
Connects unit testing with functional programming, integration testing, property-based testing, and code coverage.

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.