Flow Runtime Faker

Flow Runtime Faker

logo

Build Status Coverage Status npm GitHub license Maintenance Donate

Motivation

Type definitions in javascript can help adding type safety for classes. But should not make more complicated property based testing. This package aims to generate random objects based on their flow definitions

Installation

yarn add flow-runtime-faker -D or npm install flow-runtime-faker --save-dev

if you use only flow and not flow-runtime. You can use this plugin by: - yarn add flow-runtime babel-plugin-flow-runtime -D or npm install flow-runtime babel-plugin-flow-runtime --save-dev - add the next configuration for tests phase on your .babelrc

    {
    ...
     "env": {
        "test": {
            "plugins": [["flow-runtime", { "assert": false, "annotate": false }]]
        }
      }
    }

Usage

import faker from 'flow-runtime-faker'

type otherType {
    fuz: 42 | 7 | 32 | "Some" | "Some Other" | false
}

type myType = {
    foo: number,
    bar: number[],
    daz: string,
    don: otherType
}

let value = fake(test)

console.log(value)
/*
type myType = {
    foo: 10,
    bar: [1,6.40],
    daz: "something",
    don: {
        fuz: 42
    }
}
*/

Support

Done? Flow Type
number
string
boolean
null
void
numeric literals
string literals
boolean literals
union
maybe
optional
arrays
subtypes
function
Avatar
Code dreamer, Creator of random stuff & sharing wizard