Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4829

Consistent Factories in Mirage

$
0
0

@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 the color?

Thanks!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4829

Trending Articles