Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dubzzz/jest-fast-check
Property based testing for Jest based on fast-check
https://github.com/dubzzz/jest-fast-check
Last synced: 2 months ago
JSON representation
Property based testing for Jest based on fast-check
- Host: GitHub
- URL: https://github.com/dubzzz/jest-fast-check
- Owner: dubzzz
- License: mit
- Archived: true
- Created: 2020-02-27T23:38:51.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-23T23:53:23.000Z (over 2 years ago)
- Last Synced: 2024-08-03T05:25:58.486Z (3 months ago)
- Language: TypeScript
- Homepage:
- Size: 478 KB
- Stars: 16
- Watchers: 2
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
⚠️⚠️⚠️ Project moved to https://github.com/dubzzz/fast-check/tree/main/packages/jest ⚠️⚠️⚠️
---
# Property based testing for Jest based on [fast-check](https://github.com/dubzzz/fast-check/)
[![Build Status](https://github.com/dubzzz/jest-fast-check/workflows/Build%20Status/badge.svg?branch=main)](https://github.com/dubzzz/jest-fast-check/actions)
[![npm version](https://badge.fury.io/js/jest-fast-check.svg)](https://badge.fury.io/js/jest-fast-check)Bring the power of property based testing framework fast-check into jest.
`jest-fast-check` simplifies the integration of fast-check into jest testing framework.## Getting started
Install `jest-fast-check` and its peer dependencies:
```bash
# With yarn
yarn add -D jest fast-check jest-fast-check# With npm
npm install --save-dev jest fast-check jest-fast-check
```## Example
```javascript
import { testProp, fc } from "jest-fast-check";// 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);
}
);
```Please note that the properties accepted by `jest-fast-check` as input can either be synchronous or asynchronous (even just `PromiseLike` instances).
## Advanced
If you want to forward custom parameters to fast-check, `testProp` accepts an optional `fc.Parameters` ([more](https://github.com/dubzzz/fast-check/blob/main/documentation/1-Guides/Runners.md#runners)).
`jest-fast-check` also comes with `.only`, `.skip` and `.todo` from jest.
```javascript
import { itProp, testProp, fc } from "jest-fast-check";testProp(
"should replay the test for the seed 4242",
[fc.nat(), fc.nat()],
(a, b) => {
return a + b === b + a;
},
{ seed: 4242 }
);testProp.skip("should be skipped", [fc.fullUnicodeString()], (text) => {
return text.length === [...text].length;
});describe("with it", () => {
itProp("should run too", [fc.nat(), fc.nat()], (a, b) => {
return a + b === b + a;
});
});
```## Minimal requirements
| jest-fast-check | jest | fast-check |
| --------------- | ------------------------------------ | -------------------- |
| ^2.0.0 | >=26.5.0(1)(2) | ^3.0.0 |
| ^1.0.0 | >=26.5.0(1)(2) | ^2.0.0(3) |- (1) any version of `jest` should be great if you are using `commonjs`
- (2) in order to use `esm` build, you may need to enable experimental features of node, see [here](./test-bundle/esm/package.json)
- (3) `fast-check@^2.0.0` for hybrid module support: `commonjs` and `esm` together