When developing or testing your application, you might need to mock data comming from a database or an endpoint. Instead of manually generating "random" data, you can use model factories. This package allows you to define a default set of attributes for each of your endpoints or models and easily mock responses.
Check out our documentation for APIs and examples at https://olavoasantos.github.io/node-factory/
If you're using yarn
:
yarn add -D node-factory
Or, if you're using npm
:
npm install --save-dev node-factory
// 1. Import the factory generator
import { factory } from 'node-factory';
// 2. Create a factory
interface User {
id: string;
name: string;
email: string;
}
const UserFactory = factory<User>(fake => ({
id: fake.datatype.uuid(),
name: fake.name.findName(),
email: fake.internet.email(),
}));
// 3. Generate data
UserFactory.make();