
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
cooky-cutter
Advanced tools
Simple, type safe* object factories for JavaScript tests. (*with TypeScript)
You need to write maintainable tests for JavaScript. The code depends on specific entity types defined in the data model. These entities might initially get stubbed out in tests (Mocha, Jest, etc) as plain objects. As complexity grows, you move to factory functions (or another package that does this) to avoid the duplication. A new column gets added, an old one gets removed or maybe an entirely new entity is added. The breaking change isn't noticed until the entire test suite runs (or maybe never).
cooky-cutter
is a light package
that leverages TypeScript to define and create factories. Simply pass the type
as a generic (assuming you already have a type or interface defined for each
entity type). Whenever the entity type changes, the factories become invalid!
npm install --save-dev cooky-cutter
# or
yarn add --dev cooky-cutter
For more documentation and examples, read the full documentation.
import { define, random, sequence } from "cooky-cutter";
// Define an interface (or type) for the entity
interface User {
id: number;
firstName: string;
lastName: string;
age: number;
}
// Define a factory that represents the defined interface
const user = define<User>({
id: random,
firstName: i => `Bob #${i}`,
lastName: "Smith",
age: sequence
});
// Invoke the factory a few times
console.log(user());
// => { id: 980711200, firstName: 'Bob #1', lastName: 'Smith', age: 1 }
console.log(user());
// => { id: 1345667839, firstName: 'Bob #2', lastName: 'Smith', age: 2 }
console.log(user());
// => { id: 796816401, firstName: 'Bob #3', lastName: 'Smith', age: 3 }
FAQs
Object factories for testing in TypeScript
The npm package cooky-cutter receives a total of 4,865 weekly downloads. As such, cooky-cutter popularity was classified as popular.
We found that cooky-cutter 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.