This plugin for Jasmine 2.x allows you to easily create data driven tests.
thisvariable works the same as it does for regular Jasmine specs
npm install jasmine-data_driven_tests
src/all.js after the source files for Jasmine. Now, you have
two global functions available to you:
Data Driven Tests:
Data Driven Tests, marked as pending:
Data Driven Tests have three basic components:
A quick example:
The call to
all above is equivalent to these native Jasmine method calls:
In the Jasmine test runner, you'll see the following output:
blank values are invalidblank values are invalid (Variant #0 <"">)blank values are invalid (Variant #1 <null>)blank values are invalid (Variant #2 <undefined>)
Since they are just regular
it's, you can click on
blank values are invalid to run every test case, or click on an individual
variant to just run that one case.
all method expands to the jasmine
it method, the
using method expands to the
using method is used to create more complex data driven tests.
The call to
using above is equivalent to these native Jasmine method calls:
And for the icing on the cake? A
using block can contain one or more
all produces these native Jasmine calls:
You can pass as many arguments to your spec function as you want:
You'll see this in the test runner:
values are greater than 0values are greater than 0 (Variant #0 <3, 1>)values are greater than 0 (Variant #1 <5, 2>)
The same holds true for the
using function as well.
Asynchronous specs are also supported as long as your callback function accepts one more argument than your dataset provides.
In the following example, the dataset provides two arguments, and the callback
function accepts three. The third argument is the
done callback in Jasmine,
which when called will complete the current spec and advance the test runner to
the next one.
xall functions are really just wrappers for
xit. Data Driven Specs are supported anywhere Jasmine is supported.
You can use the
this keyword in your data driven tests just like you can with
You can really clean up your repetitive specs, but you should follow some guidelines to ensure accurate and readable tests.
No further feature enhancements are planned, however suggestions are always welcome. Just open a new Issue on GitHub explaining the feature request, and the use case for it.
Bug reports should also be managed at GitHub in the Issue Tracker for this repository.