flow-runtime-faker

1.0.132 • Public • Published

logo

Build Status codecov 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

Package Sidebar

Install

npm i flow-runtime-faker

Weekly Downloads

176

Version

1.0.132

License

MIT

Unpacked Size

4.2 MB

Total Files

18

Last publish

Collaborators

  • kanekotic