This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const personGen = gen.object({ | |
name: gen.string, | |
age: gen.int, | |
orders: gen.array(gen.object({ | |
trackingId: gen.int, | |
name: gen.string | |
})), | |
// ... | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ result: false, | |
'failing-size': 2, | |
'num-tests': 3, | |
fail: [ 2, -1 ], | |
shrunk: | |
{ 'total-nodes-visited': 2, | |
depth: 1, | |
result: false, | |
smallest: [ 0, -1 ] } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var testcheck = require('testcheck'); | |
var gen = testcheck.gen; | |
testcheck.check(testcheck.property( | |
[gen.int, gen.int], // generate two random integers | |
function (a, b) { | |
// check that the sum of the integers is always greater than any one number | |
return a + b >= a && a + b >= b; | |
} | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {sampleOne} from 'babel-plugin-transform-flow-to-gen/api'; | |
type Person = { | |
name: string, | |
age: number, | |
setName: (name: string) => Person | |
}; | |
const person = sampleOne(Person()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type {Person} from './types'; | |
export default function setName(person: Person, name: string): Person { | |
return { | |
...person, | |
name | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import setName from './setName'; | |
import {types} from 'babel-plugin-transform-flow-to-gen/api'; | |
import type {Person} from './types'; | |
require('jasmine-check').install(); | |
describe('setName', () => { | |
it.check('sets a new name', [Person(), types.string()], (person, newName) => { | |
const next = setName(person, newName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uuid from 'uuid-v4'; | |
import {sample} from 'babel-plugin-transform-flow-to-gen/api'; | |
import type {$Gen} from 'babel-plugin-transform-flow-to-gen/Gen'; | |
// FYI, | |
// type $Gen<T, _U> = T; | |
type User = { | |
id: $Gen<string, uuid>, // $Gen only supports references to function calls | |
name: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {sampleOne} from 'babel-plugin-transform-flow-to-gen/api'; | |
type Person = { | |
name: string, | |
age: number | |
} | |
function setName(person: Person, name: string): Person { | |
return { | |
...person, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {sampleOne, types} from 'babel-plugin-transform-flow-to-gen/api'; | |
const personGen = | |
types.plainObject({ | |
name: types.string(), | |
age: types.number() | |
}); | |
console.log(sampleOne(personGen)); | |
// { "name": "rJJ9", "age": -1 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {sample, sampleOne, types} from 'babel-plugin-transform-flow-to-gen/api'; | |
import type {Animal, Dog} from './types'; | |
const dogGen = Animal(types.literal('dog')); | |
const anySpeciesGen = Animal(types.string()); | |
const dog = sampleOne(dogGen); | |
console.log(dog); | |
// { "species": "dog", "name": "ahKL9p" } |