mocha-testdata
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.
Install
$ npm install --save-dev mocha-testdata
Usage
Here's a basic example with the BDD interface:
;; describe'My test suite', ;
And the same example with the TDD interface:
;; suite'My test suite', ;
API
Assuming:
;
testData.given(data)
Defines set of test data for a test case.
data
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:
;; suite'My test suite', ;
testData.givenAsync(data)
Defines set of test data for an async test case.
data
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:
;; suite'My async test suite', ;
TypeScript notes
The following use-cases are currently supported by included TypeScript typings:
; // simple datagiven1, 2, 3, 4.it"One", arg;givenAsync1, 2, 3, 4.it"Two",done; // simple predefined data;givendata.it"Three", arg;givenAsyncdata.it"Four",done; // complex datagiven, .it"Five",a;givenAsync, .it"Six",done; // complex predefined data; // explicit typing is required here, type inference is not good enough in TypeScript 1.8.9givencomplexData.it"Seven",a;givenAsynccomplexData.it"Eight",done; // structured datagiven, .it"Nine", arg.a;givenAsync, .it"Ten",arg.a && done; // structured predefined data;givenstructuredData.it"Eleven", arg.a;givenAsyncstructuredData.it"Twelve",arg.a && done;
Contributing
-
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.
License
MIT © Pandell Technology