
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
test-randomizing
Advanced tools
Test Randomizing helps you to build randomized objects or class instances for your tests.
Helps you to build randomized objects for your tests.
import {
freezeMerge,
merge,
RandomFn,
freezeMergeFactory
} from "https://x.nest.land/test_randomizing@0.5.0/mod.ts";
// or
import {
freezeMerge,
merge,
RandomFn,
freezeMergeFactory
} from "https://deno.land/x/test_randomizing@0.5.0/mod.ts";
npm install --save-dev test-randomizing
# or
yarn add --dev test-randomizing
You can use test randomizing in JavaScript and TypeScript projects.
We recommend using a library (like fakerjs or deno faker) to create randomized objects.
Deno example
./examples/deno:
import { freezeMergeFactory } from "https://x.nest.land/test_randomizing@0.5.0/mod.ts";
import { faker } from "https://deno.land/x/deno_faker@v1.0.3/mod.ts";
import { assertEquals } from "https://deno.land/std@0.119.0/testing/asserts.ts";
// Implementation
const generateEmail = (person: Person) => {
if (!person.companyName || (!person.firstName && !person.lastName)) {
return undefined;
}
return `${person.firstName}.${person.lastName}@${person.companyName}.com`;
};
// Types
type Person = {
firstName: string;
lastName: string;
companyName: string;
};
// Test code
const randomPerson = freezeMergeFactory<Person>({
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
companyName: faker.company.companyName(),
});
Deno.test("consist of firstname.lastname@companyname.com", () => {
const person = randomPerson({
firstName: "steve",
lastName: "jobs",
companyName: "apple",
});
const email = generateEmail(person);
assertEquals(email, "steve.jobs@apple.com");
});
Deno.test("returns undefined if firstName and lastName is empty", () => {
const person = randomPerson({ firstName: "", lastName: "" });
const email = generateEmail(person);
assertEquals(email, undefined);
});
Deno.test("returns undefined if companyName is empty", () => {
const person = randomPerson({ companyName: "" });
const email = generateEmail(person);
assertEquals(email, undefined);
});
Typescript Node.js example
./examples/nodejs-ts:
import { DeepPartial, freezeMerge, RandomFn } from "test-randomizing";
import { company, name } from "faker";
// Implementation
const generateEmail = (person: Person) => {
if (!person.companyName || (!person.firstName && !person.lastName)) {
return undefined;
}
return `${person.firstName}.${person.lastName}@${person.companyName}.com`;
};
// Types
type Person = {
firstName: string;
lastName: string;
companyName: string;
};
// Test code
const randomPerson: RandomFn<Person> = (override?: DeepPartial<Person>) =>
freezeMerge({
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
companyName: faker.company.companyName(),
}, override);
test("consist of firstname.lastname@companyname.com", () => {
const person = randomPerson({
firstName: "steve",
lastName: "jobs",
companyName: "apple",
});
const email = generateEmail(person);
expect(email).toEqual("steve.jobs@apple.com");
});
test("returns undefined if firstName and lastName is empty", () => {
const person = randomPerson({ firstName: "", lastName: "" });
const email = generateEmail(person);
expect(email).toBeUndefined();
});
test("returns undefined if companyName is empty", () => {
const person = randomPerson({ companyName: "" });
const email = generateEmail(person);
expect(email).toBeUndefined();
});
More complete examples in the ./examples directory:
./examples/nodejs-ts./examples/denoMIT License
Copyright (c) 2021 Ti/o
Use vr (Velociraptor) to run all commands like vr check and vr publish.
FAQs
Test Randomizing helps you to build randomized objects or class instances for your tests.
The npm package test-randomizing receives a total of 314 weekly downloads. As such, test-randomizing popularity was classified as not popular.
We found that test-randomizing demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.