Write Property-Based Tests with fast-check and Claude
Unit tests check the cases you thought of — property-based tests check the cases you didn't. Ask Claude to write them and it'll find the invariants you'd never think to enumerate manually.
claude "Read src/utils/currency.ts and write property-based tests using fast-check. Identify the mathematical invariants — commutativity, idempotency, round-trip encoding, boundary behaviours — and test each one with generated inputs including edge cases like zero, negative values, and floating-point precision."
Claude identifies the right properties for your domain: a sorting function should be stable and produce the same length output; a parser should round-trip any valid input; a price formatter should never lose precision.
// Claude generates tests like this
it('formatting then parsing is a round trip', () => {
fc.assert(
fc.property(fc.integer({ min: 0, max: 10_000_00 }), (amount) => {
expect(parseCurrency(formatCurrency(amount))).toBe(amount);
})
);
});
For APIs and data pipelines, property tests are especially valuable:
claude "Write fast-check property tests for the UserSchema Zod validator. Test that any object satisfying the schema passes validation, that objects with required fields missing always fail, and that no valid input can cause an unhandled exception."
Claude can also shrink failures for you — when fast-check finds a counterexample, ask Claude to explain why that specific minimal case breaks the property.
Property tests find bugs that 1000 hand-written unit tests won't — and Claude writes them faster than you can dream up the invariants.
Log in to leave a comment.
Set up Claude Code as an automated reviewer in your CI pipeline — on every pull request, it reads the diff, checks for bugs, security issues, missing tests, and convention violations, then posts its findings as a PR comment. Your human reviewers get a head start because the obvious issues are already flagged before they look.
Before deploying, tell Claude to read your project — migrations, environment variables, queue workers, scheduled tasks, caching, third-party integrations — and generate a deployment checklist that's specific to your app. Not a generic "did you run migrations?" list, but one that knows YOUR infrastructure and catches the things YOUR deploy can break.
Instead of writing a README from memory or copying a template, tell Claude to read your project and generate one that's actually accurate — real setup instructions from your config, real architecture from your directory structure, real API examples from your routes, and real prerequisites from your dependency files.