Magically creates a random fake data such as names, addresses, and phone numbers based in your SimpleSchema. Good for testing fixtures.
Install using Meteor's package management system:
> meteor add gbit:fakefill
$ meteor test-packages ./
You can call Fakefill from your Collection namespace
Do you want to easily seed your collection with 10 fake docs? Just do it:
var docs = Authors.fakefill().insert(number, overrides, options);
=> [ { profile: { firstName: '...', lastName: '...', email: '...' }, ..., ..., ... } ]
This method inserts the number you specified of random documents to your collection.
If you want to omit some field, just pass an array in options.omit
:
var docs = Authors.fakefill().insert(number, overrides, {
omit: ['email']
});
=> [ { profile: { firstName: '...', lastName: '...' }, ..., ..., ... } ]
This method doesn't insert nothing to your collection, just returns a array with random documents.
var Authors = new Mongo.Collection('authors');
Authors.attachSchema(new SimpleSchema({
profile: {
type: new SimpleSchema({
firstName: {
type: String
},
lastName: {
type: String
},
email: {
type: String
}
})
}
}));
var docs = Authors.fakefill().gen(10); //
=> [ { profile: { firstName: '...', lastName: '...', email: '...' }, ..., ..., ... } ]
Do you want to seed your collection in a single line with zero effort?
// Create for me 10 random users, please.
Users.fakefill().gen(10);
You can get a random totally filled doc just passing a schema to Fakefill.fromSchema
.
Fakefill will load all the fields and generate the proper data for each of them.
So just relax and:
var doc = Fakefill.fromSchema(new SimpleSchema({
userName: {
type: String,
label: 'Site username'
},
email: {
type: SimpleSchema.RegEx.Email,
label: 'Your email'
}
}));
=> { username: 'Maria_Juana666', email: '[email protected]' }
But if you're unhappy with the generated data of a field, you can pass an override:
var doc = Fakefill.fromSchema(new SimpleSchema({
userName: {
type: String,
label: 'Site username'
},
email: {
type: SimpleSchema.RegEx.Email,
label: 'Your email'
}
}), {
userName: function(){
return 'oh my god';
}
});
=> { username: 'oh my god', email: '[email protected]' }
That's it.
This method is just a shortcut for Fakefill(Collection.simpleSchema())
var doc = Fakefill.genDoc(Users);
=> { username: 'Maria_Juana666', email: '[email protected]', ... }
Fakefill.setLocale('pt_BR');
Set the language locate you want. See the supported locales:
- de
- de_AT
- de_CH
- en
- en_AU
- en_BORK
- en_CA
- en_GB
- en_IE
- en_IND
- en_US
- en_au_ocker
- es
- fa
- fr
- fr_CA
- ge
- it
- ja
- ko
- nb_NO
- nep
- nl
- pl
- pt_BR
- ru
- sk
- sv
- tr
- uk
- vi
- zh_CN
- zh_TW
This package includes gbit:faker, so you can use it too calling faker
.
- Fakefill don't fill up correctly schema fields with type [Type]
- Autodetect for field with String type is too slow (hope improve this soon) :(
Accepting pull requests that increase Fakefill perfomance.