@datx/test-data-factory
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

@datx/test-data-factory

Rather than instancing random models each time you want to test something in your system you can instead use a factory that can create fake data. This keeps your tests consistent and means that they always use data that replicates the real thing. If your tests work off objects close to the real thing they are more useful and there's a higher chance of them finding bugs.

npm install --save-dev @datx/test-data-factory
yarn add --dev @datx/test-data-factory

Basic usage

We use the build function to create a factory. You give a factory an object of fields you want to define:

import { createFactory } from '@datx/test-data-factory';
import { createClient } from './create-client';
import { User } from './models/User';

const client = createClient();
const factory = createFactory(client);

const userFactory = factory(User, {
  fields: {
    name: 'John',
  },
});

const user = userFactory();

console.log(user); // => { name: 'John'}

Docs

Inspired by

Troubleshooting

Having issues with the library? Check out the troubleshooting page or open an issue.


Build Status

License

The MIT License

Credits

datx is maintained and sponsored by Infinum.

Dependents (0)

Package Sidebar

Install

npm i @datx/test-data-factory

Weekly Downloads

76

Version

3.0.0

License

MIT

Unpacked Size

70 kB

Total Files

19

Last publish

Collaborators

  • infinumcom