UNPKG

@fast-check/vitest

Version:

Property based testing for Vitest based on fast-check

27 lines (26 loc) 1.31 kB
import * as fc from "fast-check"; import { Arbitrary, GeneratorValue, Parameters, assert, asyncProperty, readConfigureGlobal } from "fast-check"; import { TestAPI } from "vitest"; //#region src/internals/types.d.ts type ExtraContext = { g: GeneratorValue; }; type It = TestAPI<ExtraContext>; type ArbitraryTuple<Ts extends [any] | any[]> = { [P in keyof Ts]: Arbitrary<Ts[P]> }; type ArbitraryRecord<Ts> = { [P in keyof Ts]: Arbitrary<Ts[P]> }; type Prop<Ts extends [any] | any[]> = (...args: Ts) => boolean | void | PromiseLike<boolean | void>; type PropRecord<Ts> = (arg: Ts) => boolean | void | PromiseLike<boolean | void>; //#endregion //#region src/internals/TestBuilder.d.ts /** * Revamped {it,test} with added `.prop` */ type FastCheckItBuilder<T> = T & ("each" extends keyof T ? T & { prop: <Ts, TsParameters extends Ts = Ts>(arbitraries: Ts extends [any] | any[] ? ArbitraryTuple<Ts> : ArbitraryRecord<Ts>, params?: Parameters<TsParameters>) => (testName: string, prop: Ts extends [any] | any[] ? Prop<Ts> : PropRecord<Ts>, timeout?: number) => void; } : T) & { [K in keyof Omit<T, "each">]: FastCheckItBuilder<T[K]> }; //#endregion //#region src/vitest-fast-check.d.ts declare const test: FastCheckItBuilder<It>; declare const it: FastCheckItBuilder<It>; //#endregion export { fc, it, test };