-
I recently started using fast-check on a few projects, long having needed a good pbt library. The arbitraries and chain/map are very easy to use, even when generating complex data types, and I was able to find and fix a few bugs in my utility library. The import { expect } from 'chai';
import { integer } from 'fast-check';
import { over } from 'mocha-foam';
describe('example properties', () => {
over('some numbers', integer(), (it) => {
it('should be even', (n: number) => {
return n % 2 === 0;
});
it('should be odd', async (n: number) => {
expect(n % 2).to.equal(1);
});
});
}); The difference is the arbitrary at the suite level, using a wrapped While writing this, I came across a few questions:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey, Here are some answers for your questions:
Actually not really. As you said the const out = fc.check(fc.property(...arbs, predicate));
if (out.failed) {
if (out.error === 'Property failed by returning false') {
// property returned false
}
else {
// property crashed
}
}
else {
// success
} But for the moment there is nothing better.
Regarding this one I have no real news. fast-check now comes with a built-in way to customize the reporter to report errors in a custom way. You may have a look to: https://github.com/dubzzz/fast-check/blob/main/documentation/Tips.md#customize-the-reported-error
No there is not. Arbitraries should be state-less they can be called multiple times in a row without being impacted by previous calls*. So fell free to re-use them from one property to another. *It is at least true for the arbitraries coming within fast-check.
The input of check is supposed to be a property. The built-in property builder of fast-check builds tuples of all the inputs. Nonetheless the typings of check seem to say |
Beta Was this translation helpful? Give feedback.
Hey,
Here are some answers for your questions:
Actually not really. As you said the
error
field will always be set in case of non-fulfill property. On fast-heck side return false or throwing is fully equivalent. The potential only thing you could do it checking for a precise error. You could probably do something like: