fast-check-bun-test
is a fork of @fast-check/vitest
, adapted to integrate property-based testing with bun:test
. It leverages the power of fast-check to generate random inputs and verify your code’s behavior under a wide range of scenarios, all within Bun’s lightweight and fast testing framework.
Install fast-check-bun-test
as a development dependency. Note that the package requires fast-check
as a peer dependency, so you must install it separately.
bun add --dev fast-check-bun-test
Here’s an example of how to use fast-check-bun-test to test a simple property:
import { test, fc } from 'fast-check-bun-test';
// Example: Verify that b is a substring of a + b + c for all strings a, b, c
test.prop([fc.string(), fc.string(), fc.string()])(
'should detect the substring',
(a, b, c) => {
return (a + b + c).includes(b);
}
);
// Same property using named values for clarity
test.prop({ a: fc.string(), b: fc.string(), c: fc.string() })(
'should detect the substring',
({ a, b, c }) => {
return (a + b + c).includes(b);
}
);
This example demonstrates how fast-check-bun-test generates random strings to confirm that concatenation preserves substring inclusion. For more advanced usage, visit the fast-check documentation.