DEV Community

Nicolas DUBIEN
Nicolas DUBIEN

Posted on

Integrate Jest and fast-check together

A few days ago, Jest released a new feature making users able to seed their runs. While not fully leveraged within Jest itself, @fast-check/jest is already using it.

It makes @fast-check/jest, the best option to integrate Jest and fast-check, as it provides an abstraction over both to ease their mutual integration.


Starting at version 1.3.0, here is how you would use it to start your new project:

npm install --save-dev jest @fast-check/jest
Enter fullscreen mode Exit fullscreen mode

Then you just have not to forget to put the --show-seed option every time you call Jest to make sure Jest will always print the seed for you.

--  "test": "jest --verbose --coverage",
++  "test": "jest --show-seed --verbose --coverage",
Enter fullscreen mode Exit fullscreen mode

Options --verbose and --coverage are just examples of possible parameters you may already pass to Jest


At that point everything is ready, have fun with fast-check and Jest and happy testing! 🎉


import { testProp, fc } from '@fast-check/jest';

// 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);
});
Enter fullscreen mode Exit fullscreen mode

Top comments (0)