willryan / factory.ts

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

Support multiple override items in build list #66

Closed mikicho closed 2 years ago

mikicho commented 2 years ago

WDYT?

So instead of:

build({a: 1});
buildList(2, {a:2});

We can do:

buildList(3, [{a: 2}, {a: 1}]);
willryan commented 2 years ago

@mikicho If I understand this right, the output of your example would be {a: 1} -> {a: 2} -> {a: 1}, because if we index off the end of the array we will repeat the first element. I think it maybe makes more sense to repeat the last element, if we repeat. Or maybe the alt version allows you to specify tuples of [count, factory] as spread args? So it would look like:

buildList([1, { a: 2 }], [2, { a: 1 }])

or some sort of chained builder syntax. I'm curious what your thoughts are.

Also, can you please add test(s) around the new buildList functionality you'd like to see? And please use ReadonlyArray<> whenever possible, so if someone happens to have a ReadonlyArray to pass into buildList, they don't have to cast it to mutable. Thanks!

mikicho commented 2 years ago

I agree. I thought I'd have time to invest in this PR. but unfortunately, I can't. I'm closing this for now.