| name | property-testing |
| description | fast-check property-based testing for pure functions. Use when writing property-based tests or testing pure functions. Triggers: "property", "fast-check", "fc.assert", "invariant", "pure function".
|
| category | web-ui |
Skill: property-testing
What Is Property-Based Testing
Instead of testing specific examples, test properties that should hold for all inputs.
import fc from 'fast-check';
test('escapeHtml never contains raw < or >', () => {
fc.assert(
fc.property(fc.string(), (s) => {
const escaped = escapeHtml(s);
expect(escaped).not.toMatch(/</);
expect(escaped).not.toMatch(/>/);
})
);
});
When to Use
- Pure functions (formatCount, escapeHtml, etc.)
- Data transformations
- Parsers/validators
- Any function where "for all inputs" matters
Rules
- Test properties, not examples
- Use
fc.assert with fc.property
- Filter inputs when needed:
.filter(s => s.length > 0)
- Run 100+ iterations in CI
Commands
bun vitest run tests/property/