0.2.0
Test Randomizing helps you to build randomized objects or class instances for your tests.
Repository
Current version released
3 years ago
Dependencies
deno.land/x
test-randomizing
Test randomizing helps you to build randomized objects for your tests.
- β 0 Dependencies
- β JavaScript
- β TypeScript
- β Deno
- β Node.js
- β esm
- β Browser
π Install
npm install --save-dev test-randomizing
π€·π½ββοΈ How to use
You can use test randomizing in JavaScript and TypeScript projects.
We recommend using a library (like faker.js) to create randomized objects.
Typescript example:
import { RandomFn, freezeMerge } from "test-randomizing";
import { name } from "faker";
type Person = {
firstName: string;
lastName: string;
gender: string;
title: string;
}
const randomPerson: RandomFn<Person> = (override?) =>
freezeMerge({
firstName: name.firstName(),
lastName: name.lastName(),
gender: name.gender(),
title: name.title(),
}, override);
const steveJobs = randomPerson({ lastName: 'Jobs', gender: 'male' });
// {
// firstName: 'Barney', // random Value
// lastName: 'Jobs',
// gender: 'male',
// title: 'Internal Functionality Strategist' // random Value
// }
const billGates = randomPerson({ lastName: 'Gates', gender: 'male' });
// {
// firstName: 'Sage', // random Value
// lastName: 'Gates',
// gender: 'male',
// title: 'International Optimization Representative' // random Value
// }
const melaniaGates = freezeMerge(bill, { firstName: 'Melania', gender: 'female' });
// {
// firstName: 'Melania',
// lastName: 'Gates',
// gender: 'female',
// title: 'International Optimization Representative' // random Value
// }
More complete examples in the ./examples
directory:
- NodeJS TypeScript
./examples/nodejs-ts
License
MIT License
Copyright (c) 2021 Ti/o
Development
Use alias drake
to run all commands like drake test
and drake build
.
alias drake="deno run -A Drakefile.ts"