FastCheck.ts
FastCheck.ts overview
Section titled “FastCheck.ts overview”Re-exports all functionality from the fast-check library, providing access to property-based testing utilities including arbitraries, property testing, and random data generation.
Fast-check allows you to write tests by specifying properties that should hold true for your functions, rather than writing specific test cases. The library then generates many random inputs to verify these properties.
Example (Checking an array reversal property)
import { FastCheck } from "effect/testing"
// Property: reverse of reverse should equal originalconst reverseProp = FastCheck.property(FastCheck.array(FastCheck.integer()), (arr: Array<number>) => { const reversed = arr.slice().reverse() const doubleReversed = reversed.slice().reverse() return JSON.stringify(arr) === JSON.stringify(doubleReversed)})
// Run the property testFastCheck.assert(reverseProp)Example (Checking string concatenation properties)
import { FastCheck } from "effect/testing"
// Test string concatenation propertiesconst concatProp = FastCheck.property(FastCheck.string(), FastCheck.string(), (a: string, b: string) => { const result = a + b return result.length === a.length + b.length && result.startsWith(a) && result.endsWith(b)})
FastCheck.assert(concatProp)Example (Generating record data for properties)
import { FastCheck } from "effect/testing"
// Generate random data for testingconst personArbitrary = FastCheck.record({ name: FastCheck.string({ minLength: 1 }), age: FastCheck.integer({ min: 0, max: 120 }), email: FastCheck.emailAddress()})
// Use in property testsconst validPersonProp = FastCheck.property(personArbitrary, (person: { name: string; age: number; email: string }) => { return person.name.length > 0 && person.age >= 0 && person.age <= 120 && person.email.includes("@")})
FastCheck.assert(validPersonProp)Since v3.10.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”re-exports
Section titled “re-exports”“fast-check” (namespace export)
Section titled ““fast-check” (namespace export)”Re-exports all named exports from the “fast-check” module.
Signature
export * from "fast-check"Since v3.10.0