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

Create an array of a type generated by a custom type builder #134

Open
Charly-xepelin opened this issue Oct 30, 2024 · 1 comment
Open

Comments

@Charly-xepelin
Copy link

Charly-xepelin commented Oct 30, 2024

This is probably more a question than a request.

I have a type called Rut.

I created a generator for it so you can do:

const personFixture = defineFixture<Person>((t) => {
    // other fields
    t.identifier.asRut();
}

How can I do if I need an array of Ruts?

Something similar to:

const personFixture = defineFixture<Person>((t) => {
    // other fields
    t.identifiers.arrayOfFixture((x) => x.asRut(), 5);
}
@jcteague
Copy link
Owner

jcteague commented Nov 14, 2024

Yeah, this is definitely a weak spot. With the current implementation you have two choices:

  1. use the as operator, which is basically the built-in escape hatch and let's you do what ever you want.
  2. create another extenstion asArrayofRut() which is going to cleanest approach if you have a lot of these. You could use it to encapsulate the as operator.

Here is the test describing it's use.

I think in your case it probably look something like:

const fixture = defineFixture<{ field: Rut[] }>((t) => 
t.field.as((inc) => [t.asRut(), t.Rut()]));

putting it in an extension would let you customize it a bit.

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