All Projects → skovy → Cooky Cutter

skovy / Cooky Cutter

Licence: mit
🍪 Object factories for testing in TypeScript

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Cooky Cutter

eslint-config-adjunct
A reasonable collection of plugins to use alongside your main esLint configuration
Stars: ✭ 39 (-64.22%)
Mutual labels:  mocha, jest
awesome-javascript-testing
🔧 Awesome JavaScript testing resources
Stars: ✭ 28 (-74.31%)
Mutual labels:  mocha, jest
react16-seed-with-apollo-graphql-scss-router4-ssr-tests-eslint-prettier-docker-webpack3-hot
Seed to create your own project using React with Apollo GraphQL client
Stars: ✭ 19 (-82.57%)
Mutual labels:  mocha, jest
patent-free-react-ecosystem-migration-plan
Patent Free React Ecosystem Migration Plan
Stars: ✭ 15 (-86.24%)
Mutual labels:  mocha, jest
Enzyme
JavaScript Testing utilities for React
Stars: ✭ 19,781 (+18047.71%)
Mutual labels:  jest, mocha
xv
❌ ✔️ zero-config test runner for simple projects
Stars: ✭ 588 (+439.45%)
Mutual labels:  mocha, jest
jest-wrap
Fluent pluggable interface for easily wrapping `describe` and `it` blocks in Jest tests.
Stars: ✭ 35 (-67.89%)
Mutual labels:  mocha, jest
Babel Plugin Tester
Utilities for testing babel plugins
Stars: ✭ 228 (+109.17%)
Mutual labels:  jest, mocha
Baretest
An extremely fast and simple JavaScript test runner.
Stars: ✭ 364 (+233.94%)
Mutual labels:  jest, mocha
Sazerac
Data-driven unit testing for Jasmine, Mocha, and Jest
Stars: ✭ 322 (+195.41%)
Mutual labels:  jest, mocha
wily
Build Node.js APIs from the command line (Dead Project 😵)
Stars: ✭ 14 (-87.16%)
Mutual labels:  mocha, jest
Public
Repository for wallaby.js questions and issues
Stars: ✭ 662 (+507.34%)
Mutual labels:  jest, mocha
qa-automation-base
There are basic projects for automation frameworks based on Kotlin/Java and TypeScript for the backend, frontend, and mobile.
Stars: ✭ 45 (-58.72%)
Mutual labels:  mocha, jest
react-multi-context
Manage multiple React 16 contexts with a single component.
Stars: ✭ 19 (-82.57%)
Mutual labels:  mocha, jest
Nodebestpractices
✅ The Node.js best practices list (December 2021)
Stars: ✭ 72,734 (+66628.44%)
Mutual labels:  jest, mocha
tropic
🍍 Test Runner Library
Stars: ✭ 29 (-73.39%)
Mutual labels:  mocha, jest
Root Cause
🔍 Root Cause is a tool for troubleshooting Puppeteer and Playwright tests. 🔎
Stars: ✭ 205 (+88.07%)
Mutual labels:  jest, mocha
Testdeck
Object oriented testing
Stars: ✭ 206 (+88.99%)
Mutual labels:  jest, mocha
Rxjs Marbles
An RxJS marble testing library for any test framework
Stars: ✭ 267 (+144.95%)
Mutual labels:  jest, mocha
Istanbuljs
monorepo containing the various nuts and bolts that facilitate istanbul.js test instrumentation
Stars: ✭ 656 (+501.83%)
Mutual labels:  jest, mocha

🍪 cooky-cutter

Simple, type safe* object factories for JavaScript tests. (*with TypeScript)

Travis branch Coverage Status npm npm type definitions

Read the Release Annoucement.

The problem

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).

The solution

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!

Installation

npm install --save-dev cooky-cutter
# or
yarn add --dev cooky-cutter

Basic Usage

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 }
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].