Options
All
  • Public
  • Public/Protected
  • All
Menu

API Reference | fast-check | Property based testing framework

Index

Enumerations

Classes

Interfaces

Type Aliases

Variables

Functions

Type Aliases

AsyncPropertyHookFunction: ((previousHookFunction: GlobalAsyncPropertyHookFunction) => Promise<unknown>) | ((previousHookFunction: GlobalAsyncPropertyHookFunction) => void)

Type of legal hook function that can be used to call beforeEach or afterEach on a IAsyncPropertyWithHooks

remarks

Since 2.2.0

BigIntArrayConstraints: { max?: bigint; maxLength?: number; min?: bigint; minLength?: number; size?: SizeForArbitrary }

Constraints to be applied on typed arrays for big int values

remarks

Since 3.0.0

Type declaration

  • Optional max?: bigint

    Upper bound for the generated int (included)

    defaultvalue

    highest possible value for this type

    remarks

    Since 3.0.0

  • Optional maxLength?: number

    Upper bound of the generated array size

    remarks

    Since 3.0.0

  • Optional min?: bigint

    Lower bound for the generated int (included)

    defaultvalue

    smallest possible value for this type

    remarks

    Since 3.0.0

  • Optional minLength?: number

    Lower bound of the generated array size

    remarks

    Since 3.0.0

  • Optional size?: SizeForArbitrary

    Define how large the generated values should be (at max)

    remarks

    Since 3.0.0

CloneValue<T, N, Rest>: [number] extends [N] ? T[] : Rest["length"] extends N ? Rest : CloneValue<T, N, [T, ...Rest]>

Type of the value produced by clone

remarks

Since 2.5.0

Type Parameters

  • T

  • N extends number

  • Rest extends T[] = []

DepthContext: { depth: number }

Instance of depth, can be used to alter the depth perceived by an arbitrary or to bias your own arbitraries based on the current depth

remarks

Since 2.25.0

Type declaration

  • depth: number

    Current depth (starts at 0, continues with 1, 2...). Only made of integer values superior or equal to 0.

    Remark: Whenever altering the depth during a generate, please make sure to ALWAYS reset it to its original value before you leave the generate. Otherwise the execution will imply side-effects that will potentially impact the following runs and make replay of the issue barely impossible.

DepthIdentifier: { [depthIdentifierSymbol]: true }

Type used to strongly type instances of depth identifier while keeping internals what they contain internally

remarks

Since 2.25.0

Type declaration

  • [depthIdentifierSymbol]: true
DepthSize: RelativeSize | Size | "max" | number | undefined

Superset of Size to override the default defined for size. It can either be based on a numeric value manually selected by the user (not recommended) or rely on presets based on size (recommended).

This size will be used to infer a bias to limit the depth, used as follow within recursive structures: While going deeper, the bias on depth will increase the probability to generate small instances.

When used with Size, the larger the size the deeper the structure. When used with numeric values, the larger the number (floating point number >= 0), the deeper the structure. +0 means extremelly biased depth meaning barely impossible to generate deep structures, while Number.POSITIVE_INFINITY means "depth has no impact".

Using max or Number.POSITIVE_INFINITY is fully equivalent.

remarks

Since 2.25.0

FalsyValue<TConstraints>: false | null | 0 | "" | typeof NaN | undefined | (TConstraints extends { withBigInt: true } ? 0n : never)

Typing for values generated by falsy

remarks

Since 2.2.0

Type Parameters

Float32ArrayConstraints: { maxLength?: number; minLength?: number; size?: SizeForArbitrary } & FloatConstraints

Constraints to be applied on float32Array

remarks

Since 2.9.0

Float64ArrayConstraints: { maxLength?: number; minLength?: number; size?: SizeForArbitrary } & DoubleConstraints

Constraints to be applied on float64Array

remarks

Since 2.9.0

GlobalAsyncPropertyHookFunction: (() => Promise<unknown>) | (() => void)

Type of legal hook function that can be used in the global parameter asyncBeforeEach and/or asyncAfterEach

remarks

Since 2.3.0

GlobalParameters: Pick<Parameters<unknown>, Exclude<keyof Parameters<unknown>, "path" | "examples">> & { afterEach?: GlobalPropertyHookFunction; asyncAfterEach?: GlobalAsyncPropertyHookFunction; asyncBeforeEach?: GlobalAsyncPropertyHookFunction; baseSize?: Size; beforeEach?: GlobalPropertyHookFunction; defaultSizeToMaxWhenMaxSpecified?: boolean }

Type describing the global overrides

remarks

Since 1.18.0

GlobalPropertyHookFunction: (() => void)

Type declaration

    • (): void
    • Type of legal hook function that can be used in the global parameter beforeEach and/or afterEach

      remarks

      Since 2.3.0

      Returns void

IntArrayConstraints: { max?: number; maxLength?: number; min?: number; minLength?: number; size?: SizeForArbitrary }

Constraints to be applied on typed arrays for integer values

remarks

Since 2.9.0

Type declaration

  • Optional max?: number

    Upper bound for the generated int (included)

    defaultvalue

    highest possible value for this type

    remarks

    Since 2.9.0

  • Optional maxLength?: number

    Upper bound of the generated array size

    remarks

    Since 2.9.0

  • Optional min?: number

    Lower bound for the generated int (included)

    defaultvalue

    smallest possible value for this type

    remarks

    Since 2.9.0

  • Optional minLength?: number

    Lower bound of the generated array size

    remarks

    Since 2.9.0

  • Optional size?: SizeForArbitrary

    Define how large the generated values should be (at max)

    remarks

    Since 2.22.0

JsonValue: boolean | number | string | null | JsonArray | JsonObject

Typings for a Json value

remarks

Since 2.20.0

LetrecLooselyTypedBuilder<T>: ((tie: LetrecLooselyTypedTie) => LetrecValue<T>)

Type Parameters

  • T

Type declaration

LetrecLooselyTypedTie: ((key: string) => Arbitrary<unknown>)

Type declaration

    • Loosely typed type for the tie function passed by letrec to the builder function we pass to it. You may want also want to use its strongly typed version LetrecTypedTie.

      remarks

      Since 3.0.0

      Parameters

      • key: string

      Returns Arbitrary<unknown>

LetrecTypedBuilder<T>: ((tie: LetrecTypedTie<T>) => LetrecValue<T>)

Type Parameters

  • T

Type declaration

LetrecValue<T>: { [ K in keyof T]: Arbitrary<T[K]> }

Type of the value produced by letrec

remarks

Since 3.0.0

Type Parameters

  • T

MaybeWeightedArbitrary<T>: Arbitrary<T> | WeightedArbitrary<T>

Either an Arbitrary<T> or a WeightedArbitrary<T>

remarks

Since 3.0.0

Type Parameters

  • T

Memo<T>: ((maxDepth?: number) => Arbitrary<T>)

Type Parameters

  • T

Type declaration

    • Output type for memo

      remarks

      Since 1.16.0

      Parameters

      • Optional maxDepth: number

      Returns Arbitrary<T>

ModelRunAsyncSetup<Model, Real>: (() => Promise<{ model: Model; real: Real }>)

Type Parameters

  • Model

  • Real

Type declaration

    • (): Promise<{ model: Model; real: Real }>
    • Asynchronous definition of model and real

      remarks

      Since 2.2.0

      Returns Promise<{ model: Model; real: Real }>

ModelRunSetup<Model, Real>: (() => { model: Model; real: Real })

Type Parameters

  • Model

  • Real

Type declaration

    • (): { model: Model; real: Real }
    • Synchronous definition of model and real

      remarks

      Since 2.2.0

      Returns { model: Model; real: Real }

      • model: Model
      • real: Real
OneOfConstraints: { depthIdentifier?: DepthIdentifier | string; depthSize?: DepthSize; maxDepth?: number; withCrossShrink?: boolean }

Constraints to be applied on oneof

remarks

Since 2.14.0

Type declaration

  • Optional depthIdentifier?: DepthIdentifier | string

    Depth identifier can be used to share the current depth between several instances.

    By default, if not specified, each instance of oneof will have its own depth. In other words: you can have depth=1 in one while you have depth=100 in another one.

    remarks

    Since 2.14.0

  • Optional depthSize?: DepthSize

    While going deeper and deeper within a recursive structure (see letrec), this factor will be used to increase the probability to generate instances of the first passed arbitrary.

    remarks

    Since 2.14.0

  • Optional maxDepth?: number

    Maximal authorized depth. Once this depth has been reached only the first arbitrary will be used.

    remarks

    Since 2.14.0

  • Optional withCrossShrink?: boolean

    When set to true, the shrinker of oneof will try to check if the first arbitrary could have been used to discover an issue. It allows to shrink trees.

    Warning: First arbitrary must be the one resulting in the smallest structures for usages in deep tree-like structures.

    remarks

    Since 2.14.0

OneOfValue<Ts>: { [ K in keyof Ts]: Ts[K] extends MaybeWeightedArbitrary<infer U> ? U : never }[number]

Infer the type of the Arbitrary produced by oneof given the type of the source arbitraries

remarks

Since 2.2.0

Type Parameters

PropertyFailure: { error: unknown; errorMessage: string }

Represent failures of the property

remarks

Since 3.0.0

Type declaration

  • error: unknown

    The original error that has been intercepted. Possibly not an instance Error as users can throw anything.

    remarks

    Since 3.0.0

  • errorMessage: string

    The error message extracted from the error

    remarks

    Since 3.0.0

PropertyHookFunction: ((globalHookFunction: GlobalPropertyHookFunction) => void)

Type declaration

RandomType: "mersenne" | "congruential" | "congruential32" | "xorshift128plus" | "xoroshiro128plus"

Random generators automatically recognized by the framework without having to pass a builder function

remarks

Since 2.2.0

RecordConstraints<T>: { requiredKeys?: T[] } | { withDeletedKeys?: boolean }

Constraints to be applied on record

remarks

Since 0.0.12

Type Parameters

  • T = unknown

RecordValue<T, TConstraints>: TConstraints extends { requiredKeys: any[]; withDeletedKeys: boolean } ? never : TConstraints extends { withDeletedKeys: true } ? Partial<T> : TConstraints extends { requiredKeys: (infer TKeys)[] } ? Partial<T> & Pick<T, TKeys & keyof T> : T

Infer the type of the Arbitrary produced by record given the type of the source arbitrary and constraints to be applied

remarks

Since 2.2.0

Type Parameters

  • T

  • TConstraints = {}

Post-run details produced by check

A failing property can easily detected by checking the failed flag of this structure

remarks

Since 0.0.7

Type Parameters

  • Ts

SchedulerSequenceItem<TMetaData>: { label: string; metadata?: TMetaData; builder: any } | (() => Promise<any>)

Define an item to be passed to scheduleSequence

remarks

Since 1.20.0

Type Parameters

  • TMetaData = unknown

Size: "xsmall" | "small" | "medium" | "large" | "xlarge"

The size parameter defines how large the generated values could be.

The default in fast-check is 'small' but it could be increased (resp. decreased) to ask arbitraries for larger (resp. smaller) values.

remarks

Since 2.22.0

SizeForArbitrary: RelativeSize | Size | "max" | undefined

Superset of Size to override the default defined for size

remarks

Since 2.22.0

Constraints implying known and optimized comparison function to be applied on uniqueArray

The defaults relies on the defaults specified by UniqueArrayConstraintsRecommended

remarks

Since 2.23.0

Type Parameters

  • T

  • U

UniqueArrayConstraintsCustomCompare<T>: UniqueArraySharedConstraints & { selector?: undefined; comparator: any }

Constraints implying a fully custom comparison function to be applied on uniqueArray

WARNING - Imply an extra performance cost whenever you want to generate large arrays

remarks

Since 2.23.0

Type Parameters

  • T

UniqueArrayConstraintsCustomCompareSelect<T, U>: UniqueArraySharedConstraints & { comparator: any; selector: any }

Constraints implying fully custom comparison function and selector to be applied on uniqueArray

WARNING - Imply an extra performance cost whenever you want to generate large arrays

remarks

Since 2.23.0

Type Parameters

  • T

  • U

UniqueArrayConstraintsRecommended<T, U>: UniqueArraySharedConstraints & { comparator?: "SameValue" | "SameValueZero" | "IsStrictlyEqual"; selector?: any }

Constraints implying known and optimized comparison function to be applied on uniqueArray

remarks

Since 2.23.0

Type Parameters

  • T

  • U

UniqueArraySharedConstraints: { depthIdentifier?: DepthIdentifier | string; maxLength?: number; minLength?: number; size?: SizeForArbitrary }

Shared constraints to be applied on uniqueArray

remarks

Since 2.23.0

Type declaration

  • Optional depthIdentifier?: DepthIdentifier | string

    When receiving a depth identifier, the arbitrary will impact the depth attached to it to avoid going too deep if it already generated lots of items.

    In other words, if the number of generated values within the collection is large then the generated items will tend to be less deep to avoid creating structures a lot larger than expected.

    For the moment, the depth is not taken into account to compute the number of items to define for a precise generate call of the array. Just applied onto eligible items.

    remarks

    Since 2.25.0

  • Optional maxLength?: number

    Upper bound of the generated array size

    remarks

    Since 2.23.0

  • Optional minLength?: number

    Lower bound of the generated array size

    remarks

    Since 2.23.0

  • Optional size?: SizeForArbitrary

    Define how large the generated values should be (at max)

    remarks

    Since 2.23.0

WithAsyncToStringMethod: { [asyncToStringMethod]: any }

Interface to implement for asyncToStringMethod

remarks

Since 2.17.0

Type declaration

WithToStringMethod: { [toStringMethod]: any }

Interface to implement for toStringMethod

remarks

Since 2.17.0

Type declaration

Variables

__commitHash: string = ...

Commit hash of the current code (eg.: COMMIT_HASH)

remarks

Since 2.7.0

__type: string = ...

Type of module (commonjs or module)

remarks

Since 1.22.0

__version: string = ...

Version of fast-check used by your project (eg.: PACKAGE_VERSION)

remarks

Since 1.22.0

asyncToStringMethod: typeof asyncToStringMethod = ...

Use this symbol to define a custom serializer for your instances. Serializer must be a function returning a promise of string (see WithAsyncToStringMethod).

Please note that:

  1. It will only be useful for asynchronous properties.
  2. It has to return barely instantly.
remarks

Since 2.17.0

cloneMethod: typeof cloneMethod = ...

Generated instances having a method [cloneMethod] will be automatically cloned whenever necessary

This is pretty useful for statefull generated values. For instance, whenever you use a Stream you directly impact it. Implementing [cloneMethod] on the generated Stream would force the framework to clone it whenever it has to re-use it (mainly required for chrinking process)

remarks

Since 1.8.0

toStringMethod: typeof toStringMethod = ...

Use this symbol to define a custom serializer for your instances. Serializer must be a function returning a string (see WithToStringMethod).

remarks

Since 2.17.0

Functions

  • For any type of values

    You may use sample to preview the values that will be generated

    example
    null, undefined, 42, 6.5, 'Hello', {}, {k: [{}, 1, 2]}
    
    remarks

    Since 0.0.7

    Returns Arbitrary<unknown>

  • For any type of values following the constraints defined by settings

    You may use sample to preview the values that will be generated

    example
    null, undefined, 42, 6.5, 'Hello', {}, {k: [{}, 1, 2]}
    
    example
    // Using custom settings
    fc.anything({
    key: fc.char(),
    values: [fc.integer(10,20), fc.constant(42)],
    maxDepth: 2
    });
    // Can build entries such as:
    // - 19
    // - [{"2":12,"k":15,"A":42}]
    // - {"4":[19,13,14,14,42,11,20,11],"6":42,"7":16,"L":10,"'":[20,11],"e":[42,20,42,14,13,17]}
    // - [42,42,42]...
    remarks

    Since 0.0.7

    Parameters

    Returns Arbitrary<unknown>

  • Run the property, throw in case of failure

    It can be called directly from describe/it blocks of Mocha. No meaningful results are produced in case of success.

    WARNING: Has to be awaited

    remarks

    Since 0.0.7

    Type Parameters

    • Ts

    Parameters

    • property: IAsyncProperty<Ts>

      Asynchronous property to be checked

    • Optional params: Parameters<Ts>

      Optional parameters to customize the execution

    Returns Promise<void>

  • Run the property, throw in case of failure

    It can be called directly from describe/it blocks of Mocha. No meaningful results are produced in case of success.

    remarks

    Since 0.0.1

    Type Parameters

    • Ts

    Parameters

    • property: IProperty<Ts>

      Synchronous property to be checked

    • Optional params: Parameters<Ts>

      Optional parameters to customize the execution

    Returns void

  • Run the property, throw in case of failure

    It can be called directly from describe/it blocks of Mocha. No meaningful results are produced in case of success.

    WARNING: Returns a promise to be awaited if the property is asynchronous

    remarks

    Since 0.0.7

    Type Parameters

    • Ts

    Parameters

    • property: IRawProperty<Ts, boolean>

      Synchronous or asynchronous property to be checked

    • Optional params: Parameters<Ts>

      Optional parameters to customize the execution

    Returns Promise<void> | void

  • asyncDefaultReportMessage<Ts>(out: never & never & never & RunDetailsSuccess<Ts> & { failed: false }): Promise<undefined>
  • asyncDefaultReportMessage<Ts>(out: RunDetails<Ts> & { failed: true }): Promise<string>
  • asyncDefaultReportMessage<Ts>(out: RunDetails<Ts>): Promise<string | undefined>
  • Run asynchronous commands over a Model and the Real system

    Throw in case of inconsistency

    remarks

    Since 1.5.0

    Type Parameters

    • Model extends object

    • Real

    • CheckAsync extends boolean

    • InitialModel extends object

    Parameters

    Returns Promise<void>

  • asyncProperty<Ts>(...args: [...arbitraries: { [ K in string | number | symbol]: Arbitrary<Ts[K]> }[], predicate: ((...args: Ts) => Promise<boolean | void>)]): IAsyncPropertyWithHooks<Ts>
  • asyncStringify<Ts>(value: Ts): Promise<string>
  • Convert any value to its fast-check string representation

    This asynchronous version is also able to dig into the status of Promise

    remarks

    Since 2.17.0

    Type Parameters

    • Ts

    Parameters

    • value: Ts

      Value to be converted into a string

    Returns Promise<string>

  • For single characters - all values in 0x0000-0xffff can be generated

    WARNING:

    Some generated characters might appear invalid regarding UCS-2 and UTF-16 encoding. Indeed values within 0xd800 and 0xdfff constitute surrogate pair characters and are illegal without their paired character.

    remarks

    Since 0.0.11

    Returns Arbitrary<string>

  • cloneIfNeeded<T>(instance: T): T
  • compareBooleanFunc<T>(): Arbitrary<((a: T, b: T) => boolean)>
  • compareFunc<T>(): Arbitrary<((a: T, b: T) => number)>
  • For comparison functions

    A comparison function returns:

    • negative value whenever a < b
    • positive value whenever a > b
    • zero whenever a and b are equivalent

    Comparison functions are transitive: a < b and b < c => a < c

    They also satisfy: a < b <=> b > a and a = b <=> b = a

    remarks

    Since 1.6.0

    Type Parameters

    • T

    Returns Arbitrary<((a: T, b: T) => number)>

  • constantFrom<T>(...values: T[]): Arbitrary<T>
  • constantFrom<TArgs>(...values: TArgs): Arbitrary<TArgs[number]>
  • For one ...values values - all equiprobable

    WARNING: It expects at least one value, otherwise it should throw

    remarks

    Since 0.0.12

    Type Parameters

    • T = never

    Parameters

    • Rest ...values: T[]

      Constant values to be produced (all values shrink to the first one)

    Returns Arbitrary<T>

  • For one ...values values - all equiprobable

    WARNING: It expects at least one value, otherwise it should throw

    remarks

    Since 0.0.12

    Type Parameters

    • TArgs extends any[] | [any]

    Parameters

    • Rest ...values: TArgs

      Constant values to be produced (all values shrink to the first one)

    Returns Arbitrary<TArgs[number]>

  • date(constraints?: { max?: Date; min?: Date }): Arbitrary<Date>
  • For date between constraints.min or new Date(-8640000000000000) (included) and constraints.max or new Date(8640000000000000) (included)

    remarks

    Since 1.17.0

    Parameters

    • Optional constraints: { max?: Date; min?: Date }

      Constraints to apply when building instances

      • Optional max?: Date
      • Optional min?: Date

    Returns Arbitrary<Date>

  • defaultReportMessage<Ts>(out: never & never & never & RunDetailsSuccess<Ts> & { failed: false }): undefined
  • defaultReportMessage<Ts>(out: RunDetails<Ts> & { failed: true }): string
  • defaultReportMessage<Ts>(out: RunDetails<Ts>): string | undefined
  • For 32-bit floating point numbers:

    • sign: 1 bit
    • significand: 23 bits
    • exponent: 8 bits

    The smallest non-zero value (in absolute value) that can be represented by such float is: 2 ** -126 * 2 ** -23. And the largest one is: 2 ** 127 * (1 + (2 ** 23 - 1) / 2 ** 23).

    remarks

    Since 0.0.6

    Parameters

    • constraints: FloatConstraints = {}

      Constraints to apply when building instances (since 2.8.0)

    Returns Arbitrary<number>

  • hash(repr: string): number
  • For mutually recursive types

    example
    type Leaf = number;
    type Node = [Tree, Tree];
    type Tree = Node | Leaf;
    const { tree } = fc.letrec<{ tree: Tree, node: Node, leaf: Leaf }>(tie => ({
    tree: fc.oneof({depthSize: 'small'}, tie('leaf'), tie('node')),
    node: fc.tuple(tie('tree'), tie('tree')),
    leaf: fc.nat()
    }));
    // tree is 50% of node, 50% of leaf
    // the ratio goes in favor of leaves as we go deeper in the tree (thanks to depthSize)
    remarks

    Since 1.16.0

    Type Parameters

    • T

    Parameters

    • builder: T extends Record<string, unknown> ? LetrecTypedBuilder<T> : never

      Arbitraries builder based on themselves (through tie)

    Returns LetrecValue<T>

  • For mutually recursive types

    example
    const { tree } = fc.letrec(tie => ({
    tree: fc.oneof({depthSize: 'small'}, tie('leaf'), tie('node')),
    node: fc.tuple(tie('tree'), tie('tree')),
    leaf: fc.nat()
    }));
    // tree is 50% of node, 50% of leaf
    // the ratio goes in favor of leaves as we go deeper in the tree (thanks to depthSize)
    remarks

    Since 1.16.0

    Type Parameters

    • T

    Parameters

    Returns LetrecValue<T>

  • mapToConstant<T>(...entries: { num: number; build: any }[]): Arbitrary<T>
  • Generate non-contiguous ranges of values by mapping integer values to constant

    example
    // generate alphanumeric values (a-z0-9)
    mapToConstant(
    { num: 26, build: v => String.fromCharCode(v + 0x61) },
    { num: 10, build: v => String.fromCharCode(v + 0x30) },
    )
    remarks

    Since 1.14.0

    Type Parameters

    • T

    Parameters

    • Rest ...entries: { num: number; build: any }[]

    Returns Arbitrary<T>

  • For mutually recursive types

    example
    // tree is 1 / 3 of node, 2 / 3 of leaf
    const tree: fc.Memo<Tree> = fc.memo(n => fc.oneof(node(n), leaf(), leaf()));
    const node: fc.Memo<Tree> = fc.memo(n => {
    if (n <= 1) return fc.record({ left: leaf(), right: leaf() });
    return fc.record({ left: tree(), right: tree() }); // tree() is equivalent to tree(n-1)
    });
    const leaf = fc.nat;
    remarks

    Since 1.16.0

    Type Parameters

    • T

    Parameters

    • builder: ((maxDepth: number) => Arbitrary<T>)

      Arbitrary builder taken the maximal depth allowed as input (parameter n)

    Returns Memo<T>

  • Randomly switch the case of characters generated by stringArb (upper/lower)

    WARNING: Require bigint support. Under-the-hood the arbitrary relies on bigint to compute the flags that should be toggled or not.

    remarks

    Since 1.17.0

    Parameters

    • stringArb: Arbitrary<string>

      Arbitrary able to build string values

    • Optional constraints: MixedCaseConstraints

      Constraints to be applied when computing upper/lower case version

    Returns Arbitrary<string>

  • modelRun<Model, Real, InitialModel>(s: ModelRunSetup<InitialModel, Real>, cmds: Iterable<Command<Model, Real>>): void
  • Run synchronous commands over a Model and the Real system

    Throw in case of inconsistency

    remarks

    Since 1.5.0

    Type Parameters

    • Model extends object

    • Real

    • InitialModel extends object

    Parameters

    • s: ModelRunSetup<InitialModel, Real>

      Initial state provider

    • cmds: Iterable<Command<Model, Real>>

      Synchronous commands to be executed

    Returns void

  • pre(expectTruthy: boolean): void
  • property<Ts>(...args: [...arbitraries: { [ K in string | number | symbol]: Arbitrary<Ts[K]> }[], predicate: ((...args: Ts) => boolean | void)]): IPropertyWithHooks<Ts>
  • record<T>(recordModel: { [ K in string | number | symbol]: Arbitrary<T[K]> }): Arbitrary<RecordValue<{ [ K in keyof T]: T[K] }>>
  • record<T, TConstraints>(recordModel: { [ K in string | number | symbol]: Arbitrary<T[K]> }, constraints: TConstraints): Arbitrary<RecordValue<{ [ K in keyof T]: T[K] }, TConstraints>>
  • For records following the recordModel schema

    example
    record({ x: someArbitraryInt, y: someArbitraryInt }): Arbitrary<{x:number,y:number}>
    // merge two integer arbitraries to produce a {x, y} record
    remarks

    Since 0.0.12

    Type Parameters

    • T

    Parameters

    • recordModel: { [ K in string | number | symbol]: Arbitrary<T[K]> }

      Schema of the record

    Returns Arbitrary<RecordValue<{ [ K in keyof T]: T[K] }>>

  • For records following the recordModel schema

    example
    record({ x: someArbitraryInt, y: someArbitraryInt }, {withDeletedKeys: true}): Arbitrary<{x?:number,y?:number}>
    // merge two integer arbitraries to produce a {x, y}, {x}, {y} or {} record
    remarks

    Since 0.0.12

    Type Parameters

    Parameters

    • recordModel: { [ K in string | number | symbol]: Arbitrary<T[K]> }

      Schema of the record

    • constraints: TConstraints

      Contraints on the generated record

    Returns Arbitrary<RecordValue<{ [ K in keyof T]: T[K] }, TConstraints>>

  • resetConfigureGlobal(): void
  • Generate an array containing all the values that would have been generated during assert or check

    example
    fc.sample(fc.nat(), 10); // extract 10 values from fc.nat() Arbitrary
    fc.sample(fc.nat(), {seed: 42}); // extract values from fc.nat() as if we were running fc.assert with seed=42
    remarks

    Since 0.0.6

    Type Parameters

    • Ts

    Parameters

    Returns Ts[]

  • Run asynchronous and scheduled commands over a Model and the Real system

    Throw in case of inconsistency

    remarks

    Since 1.24.0

    Type Parameters

    • Model extends object

    • Real

    • CheckAsync extends boolean

    • InitialModel extends object

    Parameters

    Returns Promise<void>

  • For custom scheduler with predefined resolution order

    Ordering is defined by using a template string like the one generated in case of failure of a {@link scheduler}

    It may be something like:

    example
    fc.schedulerFor()`
    -> [task\${2}] promise pending
    -> [task\${3}] promise pending
    -> [task\${1}] promise pending
    `

    Or more generally:

    fc.schedulerFor()`
    This scheduler will resolve task ${2} first
    followed by ${3} and only then task ${1}
    `

    WARNING: Custom scheduler will neither check that all the referred promises have been scheduled nor that they resolved with the same status and value.

    WARNING: If one the promises is wrongly defined it will fail - for instance asking to resolve 5 while 5 does not exist.

    remarks

    Since 1.25.0

    Type Parameters

    • TMetaData = unknown

    Parameters

    Returns ((_strs: TemplateStringsArray, ...ordering: number[]) => Scheduler<TMetaData>)

      • (_strs: TemplateStringsArray, ...ordering: number[]): Scheduler<TMetaData>
      • For custom scheduler with predefined resolution order

        Ordering is defined by using a template string like the one generated in case of failure of a {@link scheduler}

        It may be something like:

        example
        fc.schedulerFor()`
        -> [task\${2}] promise pending
        -> [task\${3}] promise pending
        -> [task\${1}] promise pending
        `

        Or more generally:

        fc.schedulerFor()`
        This scheduler will resolve task ${2} first
        followed by ${3} and only then task ${1}
        `

        WARNING: Custom scheduler will neither check that all the referred promises have been scheduled nor that they resolved with the same status and value.

        WARNING: If one the promises is wrongly defined it will fail - for instance asking to resolve 5 while 5 does not exist.

        remarks

        Since 1.25.0

        Parameters

        • _strs: TemplateStringsArray
        • Rest ...ordering: number[]

        Returns Scheduler<TMetaData>

  • For custom scheduler with predefined resolution order

    WARNING: Custom scheduler will not check that all the referred promises have been scheduled.

    WARNING: If one the promises is wrongly defined it will fail - for instance asking to resolve 5 while 5 does not exist.

    remarks

    Since 1.25.0

    Type Parameters

    • TMetaData = unknown

    Parameters

    • customOrdering: number[]

      Array defining in which order the promises will be resolved. Id of the promises start at 1. 1 means first scheduled promise, 2 second scheduled promise and so on.

    • Optional constraints: SchedulerConstraints

    Returns Scheduler<TMetaData>

  • Gather useful statistics concerning generated values

    Print the result in console.log or params.logger (if defined)

    example
    fc.statistics(
    fc.nat(999),
    v => v < 100 ? 'Less than 100' : 'More or equal to 100',
    {numRuns: 1000, logger: console.log});
    // Classify 1000 values generated by fc.nat(999) into two categories:
    // - Less than 100
    // - More or equal to 100
    // The output will be sent line by line to the logger
    remarks

    Since 0.0.6

    Type Parameters

    • Ts

    Parameters

    • generator: IRawProperty<Ts, boolean> | Arbitrary<Ts>

      IProperty or Arbitrary to extract the values from

    • classify: ((v: Ts) => string | string[])

      Classifier function that can classify the generated value in zero, one or more categories (with free labels)

        • (v: Ts): string | string[]
        • Parameters

          • v: Ts

          Returns string | string[]

    • Optional params: number | Parameters<Ts>

      Integer representing the number of values to generate or Parameters as in assert

    Returns void

  • stream<T>(g: IterableIterator<T>): Stream<T>
  • stringify<Ts>(value: Ts): string
  • For single unicode characters defined in the BMP plan - char code between 0x0000 (included) and 0xffff (included) and without the range 0xd800 to 0xdfff (surrogate pair characters)

    remarks

    Since 0.0.11

    Returns Arbitrary<string>

  • uuidV(versionNumber: 2 | 1 | 3 | 4 | 5): Arbitrary<string>

Generated using TypeDoc