Reference plugin

The Reference plugin is an example extension of the fixture factory that allows embeding other models into your definition. It is enabled by default.

Embed another model in your fixture

fixtureFactory.register('user',{
  type: 'admin',
  firstName: 'Daniel'
});

fixtureFactory.register('role',{
  id: 'random.uuid',
  name: 'internet.userName'
});

fixtureFactory.generateOne('user', {
  role: 'model.role'  
});

expect

{
  type: 'admin',
  firstName: 'Daniel',
  role:
  {
     id: '15751f0a-569d-4789-89cc-8f7c8405f007',
     name: 'German_Glover10'
  }
}

Embed another model in your fixture and provide properties

fixtureFactory.register('user',{
  type: 'admin',
  firstName: 'Daniel'
});

fixtureFactory.register('role',{
  id: 'random.uuid',
  name: 'internet.userName'
});

fixtureFactory.generateOne('user', {
  role: {
    method: 'model.role',
    reference: {
      properties: {
        active: true
      }
    }
  }
});

expect

{
  type: 'admin',
  firstName: 'Daniel',
  role:
  {
    id: '8b23b7f8-c14b-4231-a768-5ecc407a5821',
    name: 'Dianna36',
    active: true
  }
}

Embed another model field in your fixture

fixtureFactory.register('user',{
  type: 'admin',
  firstName: 'Daniel'
});

fixtureFactory.register('role',{
  id: 'random.uuid',
  name: 'internet.userName'
});

fixtureFactory.generateOne('user', {
  roleId: 'model.role.id'  
});

expect

{
  type: 'admin',
  firstName: 'Daniel',
  roleId: '17b6ec69-606d-4e97-b2c5-4eb9b3507e32'
}