Last active
November 17, 2016 15:06
-
-
Save AZaviruha/4d16a1bc77df045492fd to your computer and use it in GitHub Desktop.
Simple helper to use JSCheck generated tests inside Mocha test runner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() ]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.