Registry / testing / fakingoose

fakingoose

JSON →
library3.0.0jsnpmunverified

fakingoose 3.0.0 is a data mocking library for Mongoose schemas that automatically generates realistic mock data based on schema definitions. It supports Mongoose Schema and Model objects, offers per-field customization via options (static values, dynamic functions, type-specific generators like email or firstname), and handles nested schemas and arrays with size control. Unlike generic fakers, fakingoose integrates directly with Mongoose and respects schema types, enums, and constraints. Currently in active development with TypeScript support.

npm install fakingoose
INSTALL
IMPORT
SIG · FAKINGOOSE
F
fakingoose
testingjavascriptv3.0.0
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.

factory
import { factory } from 'fakingoose'
const fakingoose = require('fakingoose'); const factory = fakingoose.factory
ESM and CJS both supported
fakingoose (default import)
import fakingoose from 'fakingoose'
import { fakingoose } from 'fakingoose'
Default export is the module itself; named exports like factory also exist
types
import type { FactoryOptions } from 'fakingoose'
TypeScript types are shipped; use type-only import for types to avoid runtime overhead

Creates a fakingoose factory from a Mongoose schema, customizes fields with email type, dynamic age, and fixed array size, then generates a single mock object.

import mongoose from 'mongoose'; import { factory } from 'fakingoose'; const userSchema = new mongoose.Schema({ name: String, email: { type: String, required: true }, age: { type: Number, min: 0, max: 120 }, isActive: Boolean, tags: [String] }); const userFactory = factory(userSchema, { email: { type: 'email' }, age: { value: () => Math.floor(Math.random() * 100) }, tags: { size: 3 } }); const fakeUser = userFactory.generate(); console.log(fakeUser);
Debug
Known issues
breakingIn fakingoose v2, `factory` was a default export; in v3+ it is a named export.
fix
Use `import { factory } from 'fakingoose'` instead of `import factory from 'fakingoose'`.
affects: >=3.0.0
gotchafactory() accepts both Schema and Model, but when a Model is passed, the generated mock does not include _id if the schema uses ObjectId with auto: false.
fix
Ensure your schema has `_id: true` or explicitly set `_id` value in options.
affects: >=1.0.0
deprecatedThe `populateWithSchema` option is deprecated in favor of `populateWithFactory` since v2.5.0.
fix
Use `populateWithFactory` and pass a factory instance.
affects: >=2.5.0 <3.0.0
gotchaOptions per field with `value` as function receive the entire generated object (including fields generated so far) as first argument, but the order of generation is not guaranteed.
fix
Do not rely on a specific generation order; use `value` functions that depend on fields that are already set, or use `generate` with overrides.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: factory is not a function
Importing `factory` as default export instead of named export (v3 change).
fix
Use `import { factory } from 'fakingoose'` or `const { factory } = require('fakingoose');`
Cannot find module 'fakingoose'
Package not installed or not in node_modules.
fix
Run `npm install fakingoose` and ensure it's in dependencies.
Argument type mismatch: Expected a Mongoose Schema or Model
Passing a plain object or an invalid schema/model.
fix
Ensure the first argument to `factory()` is a `mongoose.Schema` instance or a `mongoose.Model`.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
mongooseoptionalpeer dependency – works with Mongoose Schema and Model
Agent activity
2 hits · last 30 days
node
2
Resources
fakingoose — npm install fakingoose · libregistry