@byndyusoft/dto-factory

Factory to generate various DTO for unit tests

Usage no npm install needed!

<script type="module">
  import byndyusoftDtoFactory from 'https://cdn.skypack.dev/@byndyusoft/dto-factory';
</script>

README

node-dto-factory

npm@latest test workflow code style: prettier semantic-release

Factory to generate various DTO for unit tests. Inspired by factory.ts.

Requirements

  • Node.js v12 LTS or later
  • npm or yarn

Install

npm install @byndyusoft/dto-factory

or

yarn add @byndyusoft/dto-factory

Usage

Example usage:

import { makeDtoFactory } from "@byndyusoft/dto-factory";
import faker from "faker";

class CharacterDto {
  public readonly id!: number;

  public readonly name!: string;
}

const characterDtoFactory = makeDtoFactory<CharacterDto>(() => ({
  id: faker.datatype.number(),
  name: faker.name.findName(),
}));

// Build character without override
console.log(characterDtoFactory.build());

// Build character with override
console.log(
  characterDtoFactory.build({
    name: "Mage",
  }),
);

// Build characters without override
console.log(characterDtoFactory.buildList(10));

// Build characters with override
console.log(
  characterDtoFactory.buildList(10, {
    name: "Mage",
  }),
);

Maintainers

License

This repository is released under version 2.0 of the Apache License.