@byndyusoft/dto-factory
v1.0.2
Published
Factory to generate various DTO for unit tests
Downloads
64
Keywords
Readme
node-dto-factory
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-js/faker";
class CharacterDto {
public readonly id!: number;
public readonly name!: string;
}
const characterDtoFactory = makeDtoFactory<CharacterDto>(() => ({
id: faker.datatype.number(),
name: faker.name.fullName(),
}));
// 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.