Add fc.assertProperty function
See original GitHub issueš Feature Request
Add a function fc.assertProperty(...args)
thatās equivalent to fc.assert(fc.property(...args))
. For consistency, there should perhaps also be fc.checkProperty
, equivalent to fc.check(fc.property(...args))
.
Motivation
Pretty much all of my tests look like fc.assert(fc.property(...args))
. Itād be nice to avoid the extra layer of nesting and just have an assertProperty
function for these common cases. I migrated from js-verify to fast-check, and love it so far, but the lack of an analog to js-verifyās assertforall
has been a bit of a nuisance.
While I could easily define this function myself, itās actually a little messy to define its type, since fc.property
has so many overloaded signatures, and TS offers no easy way to have my wrapper function inherit all those overloads, so Iād have to copy and paste them.
Example
it('should satisfy some property', () => {
fc.assertProperty(fc.boolean(), (bool) => true);
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:9 (4 by maintainers)
Top GitHub Comments
So first of all, Mocha suggests you not use arrow functions if you want to be able to utilize mocha internals at all, which I expect you might.
I think the interface could be even simpler than suggested above. If I work from the project description toward an implementation instead of vice versa, then I think tests would look something like this:
Thatās it. All the magic is on one line. Everything else is bog-standard mocha, jest, or whatever. Nothing new to learn, no weird stack traces or unusual breakpoint stepping.
Thanks a lot for the suggestion. This is indeed a recurring question or suggestion for the lib. And I really think it will be useful to come with it quickly.
IMO one cool thing would be to directly provide test wrappers, such as
it
ortest
, with property based capabilities.My target will be to provide some kind of
itProp
that could be used as follow:It would directly wrap
it
,fc.assert
andfc.property
behind a single function.I initially drafted this suggestion for
ava
but Iāll soon implement it for others (see https://github.com/dubzzz/ava-fast-check/).@ethanresnick Would it fit your need? If so Iāll come back to you as soon as I get an implementation for other test runners.