-
Notifications
You must be signed in to change notification settings - Fork 440
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
Inject Faker into the Mirage.Factory attribute's closure #153
Conversation
Thanks for the PR! I'm wondering if we can make it even simpler, something like import Mirage, {faker} from 'ember-cli-mirage';
export default Mirage.Factory.extend({
name: faker.name.firstName
}); |
I've also thought it would be nice to have some way to specify a list of data to pull from, is this possible with Faker? For example, I like seeding my dev database with actual ted events so I can see what the UI will actually look like. I've done something like this before export default Mirage.Factory.extend({
title: i => {
var list = [
'TED2011',
'TED Women 2011',
'TED Global 2012',
'TED 2013',
'TED 2014',
'TED Active 2014'
];
return list[i % list.length];
}
}); but it would be really nice to be able to do export default Mirage.Factory.extend({
title: faker.list(
'TED2011',
'TED Women 2011',
'TED Global 2012',
'TED 2013',
'TED 2014',
'TED Active 2014'
)
}); or something like that. |
Importing faker looks and feels better. The latest version exports fakers, so you can do it like you mentioned. import Mirage, {faker} from 'ember-cli-mirage';
export default Mirage.Factory.extend({
name: faker.name.firstName
}); But the project is using an old version of Babel, so I had to add two import lines in the dummy test app import Mirage from 'ember-cli-mirage';
import { faker } from 'ember-cli-mirage'; As for the list helper, I created a helper method which gets exported as well. You can now do something like that and it will select a value from the list you have provided (the example will work with Babel 5) import Mirage, { cycle } from 'ember-cli-mirage';
export default Mirage.Factory.extend({
title: cycle('TED2011', 'TED2012')
}); If you think it's better to name it list or/and merge it into faker, let me know. |
I had a change of hearts and decided to integrate list helpers into faker, but I created two helpers - random and cycle. One selects a random value from a list, the other one cycles them. import Mirage, { faker } from 'ember-cli-mirage';
export default Mirage.Factory.extend({
name: faker.list.random('Jane', 'John'),
age: faker.list.cycle(30, 40, 50)
}); |
love this, exactly what I was thinking! thanks for your help! |
Inject Faker into the Mirage.Factory attribute's closure
This looks great! |
Thank you @seanpdoyle @samselikoff do you want me to create a PR with an update to the docs explaining about faker? |
@mupkoo that would be great! Since it's a backwards-compatible new feature we'll release it in 0.1.3, but let's not worry about making a new version of the docs for 0.1.2. We should add a note that says |
And we should also make Latest say |
Ok. Can you tell me where I can find the documentation? |
yep |
@mupkoo Any updates on the docs? |
@seawatts I haven't had any free time those days, but I think I will manage to create a PR this week |
@mupkoo 👍 Thanks! |
faker docs added: http://www.ember-cli-mirage.com/docs/v0.1.x/factories/#using-fakerjs |
Woot 👍
|
Awesome! 👍 :) |
Inject Faker into the Mirage.Factory attribute's closure, so you can do something like
Let me know what do you think and I will add it do the documentation.