-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Description
🚀 Feature Proposal
Property based testing can be seen as some kind of fuzzing approach. It makes users able to cover a wider range of inputs with a single test.
Motivation
fast-check proved very useful on Jest and was behind the following issues:
toEqualnot symmetric for Set #7975toStrictEqualfails to distinguish 0 from 5e-324 #7941toStrictEqualdoes not consider arrays with objects having undefined values correctly #7937 (for this one, the tests offast-checkfailed because of the regression so I started to dig a bit and run property based on expect of Jest to see if I would be able to find other bugs like this one)
It is currently being added in the test suites of Jest itself: #8012
Example
I think the integration of fast-check within Jest could be something like the one I did for ava: https://github.com/dubzzz/ava-fast-check/ but I am very opened to discussions on this point.
My current wrapper works as follow:
- It provides
testProp- and certainlyitPropfor Jest - Its signature is:
testProp(testName, generators, property) - What's great with this wrapper is that it adds the seed next to the test name so that the user can have access to the seed even in case the test goes into an infinite loop (if and only if Jest can stop it in this case).
// for all a, b, c strings
// b is a substring of a + b + c
testProp('should detect the substring', [fc.string(), fc.string(), fc.string()], (a, b, c) => {
return (a + b + c).includes(b);
});or maybe:
// for all a, b, c strings
// b is a substring of a + b + c
test.prop('should detect the substring', [fc.string(), fc.string(), fc.string()], (a, b, c) => {
return (a + b + c).includes(b);
});Pitch
Jest is a very successful testing framework.
Adding property based testing directly within Jest would give the community a new way to check their code. It might help the JavaScript community to detect new bugs they even not though about before. fast-check has already been useful in many projects, see https://github.com/dubzzz/fast-check/blob/master/documentation/IssuesDiscovered.md