DEV Community

Nicolas DUBIEN
Nicolas DUBIEN

Posted on

2

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

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay