Skip to content

adamlacombe/node-factory

 
 

Repository files navigation

Node Factory

version issues issues

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.

Docs

Check out our documentation for APIs and examples at https://olavoasantos.github.io/node-factory/

Installation

If you're using yarn:

yarn add -D node-factory

Or, if you're using npm:

npm install --save-dev node-factory

Usage

// 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.random.uuid(),
  name: fake.name.findName(),
  email: fake.internet.email(),
}));

// 3. Generate data
UserFactory.make();

Author

About

Easy way to generate random data for your tests

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 96.9%
  • JavaScript 3.1%