
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
mocha-testdata
Advanced tools
Multiple test cases per mocha test
Allows specifying multiple test cases for each mocha test.
This package was inspired by the given method in Pavlov.
$ npm install --save-dev mocha-testdata
Here's a basic example with the BDD interface:
import * as assert from assert;
import { given } from mocha-testdata;
describe('My test suite', function () {
given('', false, null, undefined).it('passes if value is falsey', function (value) {
assert.ok(!value);
});
});
And the same example with the TDD interface:
import * as assert from assert;
import { given } from mocha-testdata;
suite('My test suite', function () {
withData('', false, null, undefined).test('passes if value is falsey', function (value) {
assert.ok(!value);
});
});
Assuming:
var testData = require('mocha-testdata');
testData.given(data)Defines set of test data for a test case.
Type: Array or argument list
Default: empty array
Values to pass to the test. If the arguments themselves are arrays, they will be passed as multiple arguments to the test function.
If a data item is an object, the description property is used to construct the individual test name.
Returns:
it: define a test case (for use with BDD interface)test: define a test case (for use with TDD & qunit interfaces)Example with multiple arguments:
import * as assert from assert;
import { given } from mocha-testdata;
suite('My test suite', function () {
given([1, 2, 3], [3, 2, 1]).test('sum to 6', function (a, b, c) {
assert.strictEqual(a + b + c, 6);
});
});
testData.givenAsync(data)Defines set of test data for an async test case.
Same as testData.given(data).
Returns:
it: define an async test case (for use with BDD interface)test: define an async test case (for use with TDD & qunit interfaces)Async test cases take a callback as their first parameter; test data are passed in subsequent parameters.
Example:
import * as assert from assert;
import { givenAsync } from mocha-testdata;
suite('My async test suite', function () {
givenAsync([1, 2, 3], [3, 2, 1]).test('sum to 6', function (done, a, b, c) {
doSomethingAsync(function () {
assert.strictEqual(a + b + c, 6);
done();
});
});
});
The following use-cases are currently supported by included TypeScript typings:
import { given, givenAsync } from "mocha-testdata";
// simple data
given(1, 2, 3, 4).it("One", arg => arg);
givenAsync(1, 2, 3, 4).it("Two", (done, arg) => done());
// simple predefined data
const data = [1, 2, 3, 4];
given(data).it("Three", arg => arg);
givenAsync(data).it("Four", (done, arg) => done());
// complex data
given([1, 2], [3, 4]).it("Five", (a, b) => a);
givenAsync([1, 2], [3, 4]).it("Six", (done, a, b) => done());
// complex predefined data
const complexData: { 0: number, 1: number }[] = [[1, 2], [3, 4]]; // explicit typing is required here, type inference is not good enough in TypeScript 1.8.9
given(complexData).it("Seven", (a, b) => a);
givenAsync(complexData).it("Eight", (done, a, b) => done());
// structured data
given({ a: 1, b: 2 }, { a: 1, b: 2 }).it("Nine", arg => arg.a);
givenAsync({ a: 1, b: 2 }, { a: 1, b: 2 }).it("Ten", (done, arg) => arg.a && done());
// structured predefined data
const structuredData = [{ a: 1, b: 2 }, { a: 1, b: 2 }];
given(structuredData).it("Eleven", arg => arg.a);
givenAsync(structuredData).it("Twelve", (done, arg) => arg.a && done());
Clone git repository
npm install (will install dev dependencies needed by the next step)
npm start (will start a file system watcher that will re-lint JavaScript and JSON files + re-run all tests when change is detected)
Make changes, don't forget to add tests, submit a pull request.
MIT © Pandell Technology
FAQs
Multiple test cases per mocha test
The npm package mocha-testdata receives a total of 1,226 weekly downloads. As such, mocha-testdata popularity was classified as popular.
We found that mocha-testdata demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.