Registry / testing / test-pantry

test-pantry

JSON →
library1.7.1jsnpmunverified

Test Pantry is a JavaScript test factory library for creating test data in a simple, fluid manner. Current stable version is 1.7.1. It uses a 'pantry' instance where you define recipes for objects (factories), then call them to generate instances. Key features include support for traits (mixing multiple factories), dynamic properties via functions, after-build hooks, sequence counters via `this.count`, list generation by passing a number, and alternative call syntax (e.g., `pantry.recipeName()`). Unlike libraries like Factory Bot or Rosie, Test Pantry emphasizes a minimalist JavaScript-native API with chaining and UMD support, though it has not seen recent updates and relies on UMD builds without ESM, which may cause issues in modern environments.

npm install test-pantry
INSTALL
IMPORT
SIG · TEST-PANTRY
T
test-pantry
testingjavascriptv1.7.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (TestPantry)
import TestPantry from 'test-pantry'
const { TestPantry } = require('test-pantry')
The package uses a default export. Named destructuring from require will result in undefined.
new TestPantry()
const pantry = new TestPantry()
const pantry = TestPantry()
TestPantry is a constructor and must be called with 'new'.
pantry.recipeFor()
pantry.recipeFor('user', { name: 'Alice' })
pantry.recipeFor('user', { name: 'Alice' })
No common mistake for this method; it accepts a name and either an object or function.

Defines two factories (object literal and function) and creates single and multiple instances.

import TestPantry from 'test-pantry' const pantry = new TestPantry() pantry.recipeFor('user', { name: 'Alice', email: 'alice@example.com', role: 'admin' }) const user = pantry('user') console.log(user) // { name: 'Alice', email: 'alice@example.com', role: 'admin' } // Using function factory with sequence pantry.recipeFor('player', function() { return { id: `${this.name}-${this.count}`, score: Math.random() } }) const players = pantry(2, 'player') console.log(players) // [ { id: 'player-1', score: 0.123 }, { id: 'player-2', score: 0.456 } ]
Debug
Known issues
gotchaProperties defined as functions in object literal factories are evaluated at creation time, not treated as values.
fix
If you want a function as a value, wrap it in another function or use a function factory.
affects: >=0.0.0
gotchaThe `this.count` in function factories is per-factory, not global. Each factory has its own counter starting at 1.
fix
Use a different mechanism if you need a global sequence.
affects: >=0.0.0
deprecatedPackage uses UMD format; there is no ESM build. Importing in modern bundlers may require specific configuration.
fix
If using ESM, consider using a bundler that can handle UMD, or look for an alternative library with ESM support.
affects: >=1.0.0
gotchaTraits are merged shallowly. Nested objects will be overwritten, not deep merged.
fix
Plan trait composition to avoid nested object conflicts.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: TestPantry is not a constructor
Calling TestPantry() without 'new' in strict ES6 or using destructured import
fix
Use 'new TestPantry()' or import default: import TestPantry from 'test-pantry'
Cannot find module 'test-pantry'
Missing dev dependency or incorrect module path
fix
Run 'npm install -D test-pantry' and ensure node_modules contains it.
TypeError: pantry.recipeFor is not a function
pantry not instantiated properly (e.g., pantry = TestPantry instead of new TestPantry)
fix
const pantry = new TestPantry()
Upgrade
Version history
1.7.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
test-pantry — npm install test-pantry · libregistry