UNPKG

2.48 kBTypeScriptView Raw
1import type { Random } from '../../random/generator/Random.js';
2import type { Stream } from '../../stream/Stream.js';
3import type { Value } from '../arbitrary/definition/Value.js';
4import type { PreconditionFailure } from '../precondition/PreconditionFailure.js';
5/**
6 * Represent failures of the property
7 * @remarks Since 3.0.0
8 * @public
9 */
10export type PropertyFailure = {
11 /**
12 * The original error that has been intercepted.
13 * Possibly not an instance Error as users can throw anything.
14 * @remarks Since 3.0.0
15 */
16 error: unknown;
17 /**
18 * The error message extracted from the error
19 * @remarks Since 3.0.0
20 */
21 errorMessage: string;
22};
23/**
24 * Property
25 *
26 * A property is the combination of:
27 * - Arbitraries: how to generate the inputs for the algorithm
28 * - Predicate: how to confirm the algorithm succeeded?
29 *
30 * @remarks Since 1.19.0
31 * @public
32 */
33export interface IRawProperty<Ts, IsAsync extends boolean = boolean> {
34 /**
35 * Is the property asynchronous?
36 *
37 * true in case of asynchronous property, false otherwise
38 * @remarks Since 0.0.7
39 */
40 isAsync(): IsAsync;
41 /**
42 * Generate values of type Ts
43 *
44 * @param mrng - Random number generator
45 * @param runId - Id of the generation, starting at 0 - if set the generation might be biased
46 *
47 * @remarks Since 0.0.7 (return type changed in 3.0.0)
48 */
49 generate(mrng: Random, runId?: number): Value<Ts>;
50 /**
51 * Shrink value of type Ts
52 *
53 * @param value - The value to be shrunk, it can be context-less
54 *
55 * @remarks Since 3.0.0
56 */
57 shrink(value: Value<Ts>): Stream<Value<Ts>>;
58 /**
59 * Check the predicate for v
60 * @param v - Value of which we want to check the predicate
61 * @param dontRunHook - Do not run beforeEach and afterEach hooks within run
62 * @remarks Since 0.0.7
63 */
64 run(v: Ts, dontRunHook?: boolean): (IsAsync extends true ? Promise<PreconditionFailure | PropertyFailure | null> : never) | (IsAsync extends false ? PreconditionFailure | PropertyFailure | null : never);
65 /**
66 * Run before each hook
67 * @remarks Since 3.4.0
68 */
69 runBeforeEach?: () => (IsAsync extends true ? Promise<void> : never) | (IsAsync extends false ? void : never);
70 /**
71 * Run after each hook
72 * @remarks Since 3.4.0
73 */
74 runAfterEach?: () => (IsAsync extends true ? Promise<void> : never) | (IsAsync extends false ? void : never);
75}