Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

FastCheck.ts

89 lines2.5 KB

1/**
2 * Re-exports `fast-check` for property-based testing.
3 *
4 * Property-based tests describe a rule that should hold for many inputs, and
5 * `fast-check` generates random examples to look for counterexamples. This
6 * module exposes the library from `effect/testing` so tests can use it alongside
7 * the other Effect testing helpers.
8 *
9 * @since 3.10.0
10 */
11​
12/**
13 * Re-exports all functionality from the fast-check library, providing access to
14 * property-based testing utilities including arbitraries, property testing,
15 * and random data generation.
16 *
17 * Fast-check allows you to write tests by specifying properties that should hold
18 * true for your functions, rather than writing specific test cases. The library
19 * then generates many random inputs to verify these properties.
20 *
21 * **Example** (Checking an array reversal property)
22 *
23 * ```ts
24 * import { FastCheck } from "effect/testing"
25 *
26 * // Property: reverse of reverse should equal original
27 * const reverseProp = FastCheck.property(
28 * FastCheck.array(FastCheck.integer()),
29 * (arr: Array<number>) => {
30 * const reversed = arr.slice().reverse()
31 * const doubleReversed = reversed.slice().reverse()
32 * return JSON.stringify(arr) === JSON.stringify(doubleReversed)
33 * }
34 * )
35 *
36 * // Run the property test
37 * FastCheck.assert(reverseProp)
38 * ```
39 *
40 * **Example** (Checking string concatenation properties)
41 *
42 * ```ts
43 * import { FastCheck } from "effect/testing"
44 *
45 * // Test string concatenation properties
46 * const concatProp = FastCheck.property(
47 * FastCheck.string(),
48 * FastCheck.string(),
49 * (a: string, b: string) => {
50 * const result = a + b
51 * return result.length === a.length + b.length &&
52 * result.startsWith(a) &&
53 * result.endsWith(b)
54 * }
55 * )
56 *
57 * FastCheck.assert(concatProp)
58 * ```
59 *
60 * **Example** (Generating record data for properties)
61 *
62 * ```ts
63 * import { FastCheck } from "effect/testing"
64 *
65 * // Generate random data for testing
66 * const personArbitrary = FastCheck.record({
67 * name: FastCheck.string({ minLength: 1 }),
68 * age: FastCheck.integer({ min: 0, max: 120 }),
69 * email: FastCheck.emailAddress()
70 * })
71 *
72 * // Use in property tests
73 * const validPersonProp = FastCheck.property(
74 * personArbitrary,
75 * (person: { name: string; age: number; email: string }) => {
76 * return person.name.length > 0 &&
77 * person.age >= 0 &&
78 * person.age <= 120 &&
79 * person.email.includes("@")
80 * }
81 * )
82 *
83 * FastCheck.assert(validPersonProp)
84 * ```
85 *
86 * @category re-exports
87 * @since 3.10.0
88 */
89export * from "fast-check"