UNPKG

@fast-check/vitest

Version:

Property based testing for Vitest based on fast-check

25 lines (24 loc) 1.01 kB
import { readConfigureGlobal } from 'fast-check'; function wrapProp(prop) { return (...args) => Promise.resolve(prop(...args)); } export function buildTestWithPropRunner(testFn, label, arbitraries, prop, params, timeout, fc) { const customParams = { ...params }; if (customParams.seed === undefined) { const seedFromGlobals = readConfigureGlobal().seed; if (seedFromGlobals !== undefined) { customParams.seed = seedFromGlobals; } else { customParams.seed = Date.now() ^ (Math.random() * 0x100000000); } } if (customParams.interruptAfterTimeLimit === undefined) { customParams.interruptAfterTimeLimit = fc.readConfigureGlobal().interruptAfterTimeLimit; } const promiseProp = wrapProp(prop); const propertyInstance = fc.asyncProperty(...arbitraries, promiseProp); testFn(`${label} (with seed=${customParams.seed})`, async () => { await fc.assert(propertyInstance, customParams); }, timeout); }