bguiz / jest-property-testing-demo

Demonstrate property based testing in Jest, including using save/re-run failed seeds
11 stars 0 forks source link

Jest property testing demo

Run

# Install all dependencies
npm install # or:
yarn install

# Run tests and then exit immediately
npm test # or
yarn test

# Run tests in watch mode, with auto-re-run, and interactive prompt
npm test -- --watch # or
yarn test -- --watch

Let's inspect the snapshots to see what these are.

So let's fix the system under test!

How it works

TestCheck brings QuickCheck style property based testing to Javascript. However, it does not give you the ability to save generated test cases that have previously failed as example based tests.

Jest is a testing framework that has the ability to save and update snapshots, which are programmatically serialised test expectations.

This demo uses snapshots in a creative manner to persist (the seeds required to reproduce) failed generated test cases, thereby generating example based test cases from them - achieving the original objective, of saving the failing test cases generated from properties.

Reading material

The idea for this came about from the following:

Author

Brendan Graetz

Licence

GPL-3.0