Skip to content

webpapaya/stahlwerk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

27 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Stahlwerk

Stahlwerk is a factory library similar to factory girl. It uses a simple API and supports traits.

API

const createUser = factory({
  id: sequence(), // increments automatically
  street: sequence((number) => `Park Street ${number}`),
  name: random([
    'Peter',
    'Maria',
    'Charles',
  ]), // choses one of the given list
  duration: random((rand) => rand), // responds a random value
  dynamicValue: execute(() => Math.random()), // executes given function on every create
  disabledAt: undefined,
  isDisabled: trait({
    disabledAt: '2000-01-01',
  }),
});

const enabledUser = createUser();
// => { id: 1, street: 'Park Street 1', name: 'Peter', disabledAt: undefined };

const disabledUser = createUser('isDisabled');
// => { id: 2, street: 'Park Street 2', name: 'Charles', disabledAt: '2000-01-01' };

const disabledUser = createUser('isDisabled', { name: 'Mike' });
// => { id: 3, street: 'Park Street 3', name: 'Mike', disabledAt: '2000-01-01' };

About

🏭 πŸ— Heavy metal factories

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published