Sazerac
Data-driven unit testing for JavaScript.
About
Sazerac is a library for data-driven testing in JavaScript. It works with mocha, jasmine, and jest. Using Sazerac, and the data-driven testing pattern in general, will reduce the complexity and increase readability of your test code.
Check out sazerac.js.org for docs and sazerac-example for examples.
Why Use It?
Let's say you have a function isPrime()
. When given a number, it returns true
or false
depending on whether the number is a prime number.
{ forvar i = 2; i < num; i++ ifnum % i === 0 return false; return num > 1;}
If you're using a framework like jasmine, your tests might look something like this:
It's a lot of code to write for only 3 test cases and such a basic function!
The same tests can be defined with Sazerac as follows:
Sazerac runs the describe
and it
functions needed for these test cases. It adds reporting messages in a consistent format based on the input and output parameters. For this example, the test report ends up looking like this:
isPrime()
when given 2
✓ should return true
when given 3
✓ should return true
when given 4
✓ should return false
Installation
Install Sazerac as an npm module and save it to your package.json
file as a development dependency:
npm install sazerac --save-dev
Import the test
and given
helper functions into your project:
Guide and API documentation
Visit sazerac.js.org.
Contributing
Yes, please do :)