@andrew1 wrote:
Hey everyone,
I'm using Mirage to mock data in my app and I was wondering if it's possible to reference one field from another to make consistent mocks. For example, let's say I have a
BarnFactory
:BarnFactory = Mirage.Factory.extend({ color() { return faker.random.arrayElement(['red', 'blue', 'green']) }, name() { return faker.random.arrayElement(['Red Barn', 'Blue Barn', 'Green Barn']) } });
this will give me a lot of variety in my mocks but it might look "wrong" in a demo to have a Barn object with the name "Blue Barn" and the color "red".
Is it possible to do something like:
BarnFactory = Mirage.Factory.extend({ color() { return faker.random.arrayElement(['red', 'blue', 'green']) }, name() { return `${this.color().toUpperCase} Barn` } })
So that the
name
is in sync with thecolor
?Thanks!
Posts: 1
Participants: 1