Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

dready/jasmine-check

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Generative property testing for Jasmine

jasmine-check adds the generative testing power of testcheck-js to Jasmine. This allows some of your Jasmine tests to accept arguments and ensure your tests pass not just under your contrived test cases but also pass for hundreds of randomly generated test cases.

Getting started

Install jasmine-check using npm.

npm install jasmine-check

Then include and install jasmine-check before your test suite.

require('jasmine-check').install();

Example

require('jasmine-check').install();

describe('MySpec', function () {

  check.it('accepts an int and a string', [gen.int, gen.string], function (x, y) {
    expect(x).toEqual(jasmine.any(Number));
    expect(y).toEqual(jasmine.any(String));
  });

});

The gen global object is provided directly by testcheck-js and defines what type of random values to generate. The test will be run numerous times with different random values, ensuring all expectations are met for every run. If a test expectation fails, then the test will re-run with "smaller" values until the smallest failing value is found which can better help explain edge cases with your test and produce consistent results, despite being initially fueled by randomness.

Options

If a test is taking a long time, needs to generate larger values, or should be run with a consistent random seed, you can alter the behavior with options:

{
  times: number;   // the number of test cases to run. Default: 100
  maxSize: number; // the maximum "size" of the test data. Default: 200
  seed: number;    // defaults to a random value from 1 to 2^32-1.
}

To use these options with your check, include an options object after the description:

check.it('runs 10 times', {times: 10}, [gen.strictPosInt], function (x) {
  expect(x).toBeGreaterThan(0);
});

To learn more about property testing, or to learn about the available value generators, check out testcheck-js.

About

Generative property testing for Jasmine

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%