Last Updated: February 27, 2017
·
2.895K
· Jérome Freyre

Jasmine - Create multiple tests case with a set of data

The snippet below will allows you to easily create multiple jasmine tests with the same code base.

It'll be helpful because if a tests fails, you won't have to debug a long time before finding the failed case

describe('Global description', function () {

        // Represent a set testable of data
        _.each([1,2,3,5,7,9,11,13,17,23 /*, etc.*/], function(v) {
            testingValues(v);
        });


        function testingValues(v) {
            beforeEach(function () {
                // Do something
            });

            describe('when returning content [v = ' + v + ']', function () {

                it('should be true', function () {
                    // Arrange
                    // Act
                    // Assert
                    expect(v > 0).toBeTruthy();
                });
            });
        }

    });