This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
| // @flow | |
| function giveMeStrings(arr: string[]): string { | |
| // do something with the array of strings | |
| } | |
| giveMeStrings('hello', 'goodbye'); | |
| /* | |
| ERROR: | |
| 7: giveMeStrings('hello', 'goodbye'); |
This file contains hidden or 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
| require('jasmine-check').install(); | |
| describe('adding numbers', () => { | |
| check.it('the sum is always greater than the parts', [gen.int, gen.int], (a, b) => { | |
| expect(a + b).toBeGreaterThanOrEqual(a); | |
| expect(a + b).toBeGreaterThanOrEqual(b); | |
| }); | |
| }); | |
| // FAIL | |
| // ● adding numbers › the sum is always greater than the parts ( 0, -1 ) |
This file contains hidden or 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 hidden or 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'; | |
| import type {Developer, JavaScript} from './types'; | |
| const javaScriptDevGen = Developer(JavaScript()); | |
| const dev = sampleOne(javaScriptDevGen); | |
| console.log(dev); | |
| // { name: 't', age: 4, preferredLanguage: { name: 'javascript' } } |
This file contains hidden or 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
| export default function append<T>(arr: T[], val: T): T[] { | |
| return [...arr, val]; | |
| } |