Skip to content

Instantly share code, notes, and snippets.

@AZaviruha
Last active November 17, 2016 15:06
Show Gist options
  • Save AZaviruha/4d16a1bc77df045492fd to your computer and use it in GitHub Desktop.
Save AZaviruha/4d16a1bc77df045492fd to your computer and use it in GitHub Desktop.
Simple helper to use JSCheck generated tests inside Mocha test runner
var isArray = require( '../../src/checkers/isArray' ) // my function to test
, JSC = require( 'jscheck' )
, _ = require( 'lodash' )
, $ = require( 'jquery' )
, chai = require( 'chai' )
, expect = chai.expect;
function JSC_it ( name, predicate, signature ) {
it( name, function ( done ) {
JSC.claim( name, function ( verdict ) {
var args = _.slice( arguments, 1 );
return verdict( predicate.apply( args ) );
}, signature );
JSC.on_result(function ( result ) {
expect( result.ok ).to.be.true;
done();
});
JSC.check();
});
};
describe( 'isArray', function () {
JSC_it( 'should be compatible with Array.isArray() method', function ( el ) {
return Array.isArray( el ) === isArray( el );
}, [ JSC.any() ]);
});
@rhythnic
Copy link

Thanks for this helper. I'm new to JSCheck, and I'm glad it can be run by mocha. I wasn't able to get it to work as written. Here's what I ended up with using ES2015. One significant difference is that the claim is passed to the check function, so check will only run for this claim and not others.

function JSC_it ( name, predicate, signature ) {
  it(name, done => 
    JSC
      .on_result( result => ( expect(result.ok).to.be.true, done() ) )
      .check( JSC.claim( name, predicate, signature ) )
  );
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment