stahlwerk
v0.2.0
Published
A minimal factory library.
Downloads
66
Maintainers
Readme
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' };