mocha-each is a utility for the Mocha testing framework that simplifies the creation of parameterized tests. It allows developers to define a single test case that runs multiple times with varying sets of input data, significantly reducing code duplication and enhancing test coverage. The current stable version is 2.0.1. While specific release cadence isn't explicitly stated, the project appears to be stable and maintained, with the latest version indicating ongoing support. Its primary differentiator is the seamless integration of data-driven testing within Mocha's existing `it` and `describe` syntax, making it straightforward to iterate over arrays of test data. A key feature is its guarantee that all parameterized test cases are executed, even if some individual cases fail, which is crucial for comprehensive test reporting. It also supports parameterization at the `describe` block level and handles asynchronous test cases effectively.
npm install mocha-eachVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `mocha-each` to run a simple parameterized test for an `add` function with different input sets, verifying both valid and invalid arguments within a Mocha test suite.
Use `.only()` sparingly and verify that all intended tests are executed. For isolating specific tests, consider running individual test files or using other Mocha filtering options.
For consistent behavior, especially in Node.js environments, stick to `const forEach = require('mocha-each');`. If you need full ESM support, check for a newer major version of `mocha-each` or use a different parameterized testing library that explicitly supports ESM.Ensure your async test case function accepts `done` as its last argument (e.g., `(arg1, arg2, done) => { ... }`) and calls `done()` upon completion, or alternatively, ensure the function returns a Promise that resolves when the asynchronous operation is complete.Change your import statement to `const forEach = require('mocha-each');` which is the officially documented and most reliable way to import the package.Ensure you have `const forEach = require('mocha-each');` at the top of your test file or within the appropriate scope.For callback-style async tests, add `done` as the last argument to your test function and call `done()` when the async operation finishes. For Promise-based async tests, ensure your test function returns the Promise.