UNPKG

@fast-check/jest

Version:

Property based testing for Jest based on fast-check

77 lines (76 loc) 2.47 kB
import * as fc from 'fast-check'; import { assert, propertyFor } from '@fast-check/worker'; import { jestExpect } from '@jest/expect'; import { buildTest } from './internals/TestBuilder.js'; function typedAssign(fun, others) { return Object.assign(fun, others); } function dummyTest() { return typedAssign(() => void 0, { concurrent: typedAssign(() => void 0, { each: () => () => void 0, failing: typedAssign(() => void 0, { each: () => () => void 0, }), only: typedAssign(() => void 0, { each: () => () => void 0, failing: typedAssign(() => void 0, { each: () => () => void 0, }), }), skip: typedAssign(() => void 0, { each: () => () => void 0, failing: typedAssign(() => void 0, { each: () => () => void 0, }), }), }), each: () => () => void 0, failing: typedAssign(() => void 0, { each: () => () => void 0, }), only: typedAssign(() => void 0, { each: () => () => void 0, failing: typedAssign(() => void 0, { each: () => () => void 0, }), }), skip: typedAssign(() => void 0, { each: () => () => void 0, failing: typedAssign(() => void 0, { each: () => () => void 0, }), }), todo: () => void 0, }); } export const init = (url, options) => { const fcExtra = { asyncProperty: propertyFor(url, options), assert: assert, readConfigureGlobal: fc.readConfigureGlobal, }; if (typeof it !== 'undefined') { if (typeof jest !== 'undefined') { return { test: buildTest(test, jest, fcExtra), it: buildTest(it, jest, fcExtra), expect: jestExpect, }; } else { return import('@jest/globals').then(({ jest }) => ({ test: buildTest(test, jest, fcExtra), it: buildTest(it, jest, fcExtra), expect: jestExpect, })); } } const dummyJest = {}; return { test: buildTest(dummyTest(), dummyJest, fcExtra), it: buildTest(dummyTest(), dummyJest, fcExtra), expect: jestExpect, }; }; export { fc };