{"id":28384,"library":"test-pantry","title":"test-pantry","description":"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.","status":"maintenance","version":"1.7.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/ndp/test-pantry","tags":["javascript","testing","factory"],"install":[{"cmd":"npm install test-pantry","lang":"bash","label":"npm"},{"cmd":"yarn add test-pantry","lang":"bash","label":"yarn"},{"cmd":"pnpm add test-pantry","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package uses a default export. Named destructuring from require will result in undefined.","wrong":"const { TestPantry } = require('test-pantry')","symbol":"default (TestPantry)","correct":"import TestPantry from 'test-pantry'"},{"note":"TestPantry is a constructor and must be called with 'new'.","wrong":"const pantry = TestPantry()","symbol":"new TestPantry()","correct":"const pantry = new TestPantry()"},{"note":"No common mistake for this method; it accepts a name and either an object or function.","wrong":"pantry.recipeFor('user', { name: 'Alice' })","symbol":"pantry.recipeFor()","correct":"pantry.recipeFor('user', { name: 'Alice' })"}],"quickstart":{"code":"import TestPantry from 'test-pantry'\n\nconst pantry = new TestPantry()\n\npantry.recipeFor('user', {\n  name: 'Alice',\n  email: 'alice@example.com',\n  role: 'admin'\n})\n\nconst user = pantry('user')\nconsole.log(user)\n// { name: 'Alice', email: 'alice@example.com', role: 'admin' }\n\n// Using function factory with sequence\npantry.recipeFor('player', function() {\n  return { id: `${this.name}-${this.count}`, score: Math.random() }\n})\n\nconst players = pantry(2, 'player')\nconsole.log(players)\n// [ { id: 'player-1', score: 0.123 }, { id: 'player-2', score: 0.456 } ]","lang":"javascript","description":"Defines two factories (object literal and function) and creates single and multiple instances."},"warnings":[{"fix":"If you want a function as a value, wrap it in another function or use a function factory.","message":"Properties defined as functions in object literal factories are evaluated at creation time, not treated as values.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use a different mechanism if you need a global sequence.","message":"The `this.count` in function factories is per-factory, not global. Each factory has its own counter starting at 1.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"If using ESM, consider using a bundler that can handle UMD, or look for an alternative library with ESM support.","message":"Package uses UMD format; there is no ESM build. Importing in modern bundlers may require specific configuration.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Plan trait composition to avoid nested object conflicts.","message":"Traits are merged shallowly. Nested objects will be overwritten, not deep merged.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Use 'new TestPantry()' or import default: import TestPantry from 'test-pantry'","cause":"Calling TestPantry() without 'new' in strict ES6 or using destructured import","error":"TypeError: TestPantry is not a constructor"},{"fix":"Run 'npm install -D test-pantry' and ensure node_modules contains it.","cause":"Missing dev dependency or incorrect module path","error":"Cannot find module 'test-pantry'"},{"fix":"const pantry = new TestPantry()","cause":"pantry not instantiated properly (e.g., pantry = TestPantry instead of new TestPantry)","error":"TypeError: pantry.recipeFor is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}