Skip to main content
Deno 2 is finally here πŸŽ‰οΈ
Learn more

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:

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"