willryan / factory.ts

A library to ease creation of factories for test data for Typescript
MIT License
425 stars 23 forks source link

Update documentation with examples for pipeline #19

Open anatoliyklamerdataart opened 5 years ago

anatoliyklamerdataart commented 5 years ago

In our project we have chance to generate test data, i want to integrate chancejs with Factory.ts It looks like I need to use pipeline? Could you update readme with example for pipeline?

willryan commented 5 years ago

@anatoliyklamerdataart I'll put a link in the readme to the pipeline spec, which contains a lengthy example.

That said, depending on what you want to do with chancejs, you can probably avoid pipelines.

If you want to use chancejs to generate random values on each iteration you should be able to just use it inside of your generator, something like:

Sync.makeFactory({
  prop: Sync.each(_ => chance.bool())
});

Of course you could define re-usable helpers so you can do something like

Sync.makeFactory({
  prop1: ChanceGen.bool(), // returns Generator<boolean>
  prop2: ChangeGen.name()
});

In fact I think maybe you can:

const ChanceGen = mapValues(chance, f => Sync.each(_ => f());

and get all chance functions in one go.