Awesome Open Source
Awesome Open Source


Data-driven unit testing for JavaScript.


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 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.

function isPrime(num) {
  for(var i = 2; i < num; i++) {
    if(num % i === 0) return false;
  return num > 1;

If you're using a framework like jasmine, your tests might look something like this:

describe('isPrime()', () => {

  describe('when given 2', () => {
    it('should return true', () => {

  describe('when given 3', () => {
    it('should return true', () => {

  describe('when given 4', () => {
    it('should return false', () => {

  // and more ...


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:

test(isPrime, () => {

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:

  when given 2
    ✓ should return true
  when given 3
    ✓ should return true
  when given 4
    ✓ should return false


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:

import { test, given } from 'sazerac'

Guide and API documentation



Yes, please do :)

Get In Touch

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Javascript (1,541,393
Jest (3,452
Unit Testing (1,687
Mocha (1,132
Assertions (513
Jasmine (388
Related Projects