fast-check-io-ts
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

fast-check-io-ts

io-ts codecs mapped to fast-check arbitraries.

Usage

import * as fc from 'fast-check';
import * as t from 'io-ts';
import { getArbitrary } from 'fast-check-io-ts';

const NonEmptyString = t.brand(
  t.string,
  (s): s is t.Branded<string, { readonly NonEmptyString: symbol }> => s.length > 0,
  'NonEmptyString'
);
const User = t.type({
  name: t.string,
  status: t.union([t.literal('active'), t.literal('inactive')]),
  handle: NonEmptyString
});

const userArb = getArbitrary(User);

console.log(fc.sample(userArb, 1)[0]); // { name: '', status: 'inactive', handle: 'M.y?>A/' }

Known issues

  • only supports predefined io-ts codecs, not custom types e.g. DateFromISOString from io-ts-types
  • getArbitrary(t.keyof({ ... })) is currently marked as error by TS, even though the codec is supported in the implementation

Package Sidebar

Install

npm i fast-check-io-ts

Weekly Downloads

393

Version

0.5.0

License

MIT

Unpacked Size

6.33 kB

Total Files

4

Last publish

Collaborators

  • giogonzo