QuickCheck for Javascript
Asked Answered
P

4

13

Is there a version of quickcheck that works for Javascript and that is well maintained? I have found several such as check.js and claire, but none of them seem to support shrinking of failing test cases, which has always struck me as the most useful part of the whole problem.

Pimple answered 12/5, 2014 at 11:39 Comment(0)
L
11

I'm creator of jsverify. I'll try constantly to make it better, bug reports and feature requests are welcomed.

There are also a list of other javascript generative testing libraries in a readme. So far I haven't found any other good alternative to the jsverify.

Lagniappe answered 12/8, 2014 at 13:31 Comment(2)
Hey, in jsverify it says "Write properties about your function that should hold true for all inputs". How then do you test functions with if/else decisions? What if for example I want to test that when a string contains "foo", that the function does something?Noiseless
@Noiseless John Hughes has advice on specifying properties at youtube.com/watch?v=G0NUOst-53U. ScottW has suggestions at fsharpforfunandprofit.com/posts/property-based-testing-2. I can recommend them, if you can grok the Haskell and F# syntax (the verbal explanations really help).Starwort
W
8

I recently released https://github.com/dubzzz/fast-check

I built it in order to answer several limitations I encountered in the existing quickcheck implementations in JavaScript.

It comes natively with a shrink feature which can shrink even combination of arbitraries (the frameworks I tried were failing on oneof like arbitraries). It also can generate large objects and arrays. By default it tends to try smaller values first in order to detect trivial edge cases while it covers all the possible inputs in next runs. Lots of other features are on-going or already available :)

Cheers, Nicolas

Wingback answered 24/5, 2018 at 22:24 Comment(1)
it's rare that I read through all the documentation at once for a library, but with yours I have! Can't wait to give this a bash. I've used and really enjoy JsVerify, so I'm very much looking forward to fast-checkDoorbell
M
4

I wrote quick_check.js, which has a nice library of generators. Shrinking is not there yet, but is planned.

Montevideo answered 14/8, 2014 at 17:16 Comment(0)
K
0

There seems to be a dearth of good quickcheck-like testing tools in javascript. However they are to be better supported in typed languages, and in fact you can write your tests in one of those languages if you wish.

To avoid dealing with runtime interop, I'd recommend going with a language which compiles to JS and runs on node.js (eg: Purescript with purescript-quickcheck), or a java-based language using the Nashorn engine provided in Java 8, for example ScalaCheck. You could even use ghcjs and the original flavor of the quickcheck library!

Kape answered 14/11, 2015 at 16:40 Comment(3)
These days I am using elm, as my interest in JavaScript is 100% about in browser operations. For backend code I use erlangPimple
I was going to include Elm and github.com/TheSeamau5/QuickCheck in my answer, but PureScript integrates better with javascript (at least until Elm 0.16..)Kape
@Kape there's a more recent property based testing library from the same author for Elm: github.com/TheSeamau5/elm-checkAlvinaalvine

© 2022 - 2024 — McMap. All rights reserved.