Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: gen is not a function #100

Open
stevenvachon opened this issue Nov 2, 2019 · 2 comments
Open

TypeError: gen is not a function #100

stevenvachon opened this issue Nov 2, 2019 · 2 comments

Comments

@stevenvachon
Copy link

const {gen} = require('testcheck');
gen({a:0});
TypeError: gen is not a function

http://leebyron.com/testcheck-js/api#gen

@camsjams
Copy link

camsjams commented Dec 14, 2019

This is weird, I agree, I think the documentation that claims gen() is a function is incorrect.

Another section of the documentation correctly describes what gen is:

gen: A collection of ValueGenerators and functions that return ValueGenerators.

Seems like the RC which implements gen() is not published on npm, see also #92

@camsjams
Copy link

@stevenvachon also you don't really need the gen function. You can use gen.array and gen.object to accomplish similar functionality.

Take this example:

// desired shape
const someDog = {
	name: 'Fido',
	age: 12
};

// create property generator
const genDogs = gen.object({
	name: gen.string,
	age: gen.int
});

// sample results of property generator
console.log('a sample of dogs:', sample(genDogs));

The console prints something like:

a sample of dogs: [ { name: '', age: 0 },
          { name: 'á', age: 1 },
          { name: 'Ñ÷', age: 1 },
          { name: '÷W', age: 3 },
          { name: '', age: -4 },
          { name: 'UÜ\u0001y¿', age: -2 },
          { name: '�\u001cÑE', age: -4 },
          { name: '�', age: -3 },
          { name: 'â', age: -3 },
          { name: '1\n�]\u0007¾Ñîº', age: -3 } ]

It is also friendly with TypeScript:

interface Dog {
	name: string;
	age: number;
}

// desired shape
const dog: Dog = {
	name: 'Fido',
	age: 12
};

// create property generator
const genDogs = gen.object({
	name: gen.string,
	age: gen.int
}) as Generator<Dog>;

// sample results of property generator
console.log('a sample of dogs:', sample(genDogs));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants