{"id":15396,"library":"test-data-bot","title":"Test Data Bot","description":"test-data-bot is a JavaScript library designed for easily generating dynamic test data for unit and integration tests. It operates agnostic of specific test runners or frameworks, providing a fluent API for defining data builders. As of version 0.8.0, it offers features like static values, unique sequences, data generation using `faker.js` (internally), per-build instance generation, incrementing IDs, random selection from a list, and array generation. The package emphasizes simplicity and flexibility, allowing for easy overrides and custom mapping functions to transform generated plain JavaScript objects into class instances or specific formats. Its release cadence appears to follow semantic versioning, with `0.x` indicating pre-1.0 development. Key differentiators include its simple, builder-pattern API and deep integration with `faker.js` without exposing it as a direct peer dependency.","status":"active","version":"0.8.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","testing","factory-bot","fixtures","test"],"install":[{"cmd":"npm install test-data-bot","lang":"bash","label":"npm"},{"cmd":"yarn add test-data-bot","lang":"bash","label":"yarn"},{"cmd":"pnpm add test-data-bot","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CommonJS `require` is shown in examples, but ESM `import` is preferred in modern JavaScript/TypeScript.","wrong":"const { build } = require('test-data-bot')","symbol":"build","correct":"import { build } from 'test-data-bot'"},{"note":"Used within a builder's `fields` definition to leverage `faker.js` for dynamic data.","wrong":"const { fake } = require('test-data-bot')","symbol":"fake","correct":"import { fake } from 'test-data-bot'"},{"note":"Provides unique, incrementing numbers per field definition, starting from 1.","wrong":"const { sequence } = require('test-data-bot')","symbol":"sequence","correct":"import { sequence } from 'test-data-bot'"},{"note":"Generates a globally unique, incrementing ID number across all builders.","wrong":"const { incrementingId } = require('test-data-bot')","symbol":"incrementingId","correct":"import { incrementingId } from 'test-data-bot'"}],"quickstart":{"code":"import { build, fake, sequence } from 'test-data-bot';\n\nconst userBuilder = build('User').fields({\n  id: sequence(x => x),\n  name: fake(f => f.name.findName()),\n  email: sequence(x => `user${x}@example.com`),\n  age: 26,\n  isActive: true,\n});\n\nconst newUser1 = userBuilder();\nconst newUser2 = userBuilder({ name: 'Jane Doe', age: 30 });\n\nconsole.log(newUser1);\n// Example output: { id: 1, name: 'John Smith', email: 'user1@example.com', age: 26, isActive: true }\nconsole.log(newUser2);\n// Example output: { id: 2, name: 'Jane Doe', email: 'user2@example.com', age: 30, isActive: true }\n\nconst adminBuilder = build('Admin').fields({\n  ...userBuilder.fields,\n  role: 'admin'\n});\n\nconst newAdmin = adminBuilder();\nconsole.log(newAdmin);\n// Example output: { id: 3, name: 'Another Name', email: 'user3@example.com', age: 26, isActive: true, role: 'admin' }","lang":"javascript","description":"Demonstrates creating a basic user builder, generating multiple unique users, overriding specific fields, and extending an existing builder for an admin user."},"warnings":[{"fix":"Understand the scope: `sequence` is per-field, `incrementingId` is global. Use `incrementingId` when truly unique IDs are needed across an entire test run, or manage custom sequencing manually for specific scenarios.","message":"The `sequence` helper generates numbers unique to each field definition, meaning `sequence(x => x)` in two different fields will both start their count from 1. Conversely, `incrementingId` provides a globally unique, auto-incrementing number across all uses.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Rely on `test-data-bot`'s public API and avoid direct `faker.js` imports if strict control over `faker.js` versions or features is required, consider using `faker.js` directly or wrapping its functions within `fake()`.","message":"While `test-data-bot` uses `faker.js` internally, the specific version of `faker.js` is managed by `test-data-bot` and is not exposed or directly controllable by the end-user. Updates to the internal `faker.js` dependency could lead to subtle changes in generated data patterns between `test-data-bot` patch versions, even without a major `test-data-bot` version bump.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always call the builder when passing it to `arrayOf` if you intend to generate objects: `arrayOf(() => myBuilder(), 3)`. The function wrapper ensures a new instance is created for each array element.","message":"When using `arrayOf(builder, count)` where `builder` is another test-data-bot builder, this will create an array containing `count` references to the *builder function itself*, not an array of generated objects. To get an array of generated objects, you must call the builder.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"For complex nested object overrides, consider using nested builders or applying a `map` function to post-process the generated data. Alternatively, ensure nested objects are themselves created by sub-builders that can be individually overridden.","message":"Overriding values by passing an object to the builder function (`userBuilder({ name: 'New Name' })`) only affects top-level fields. For deeply nested objects that are defined within `fields`, a simple override will replace the entire nested object rather than merging properties.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure correct import syntax: `const { build, fake } = require('test-data-bot');` for CommonJS or `import { build, fake } from 'test-data-bot';` for ESM.","cause":"Attempting to use `build` without correct destructuring for CommonJS `require` or using `require` in an ESM context.","error":"TypeError: build is not a function"},{"fix":"All `faker.js` methods must be accessed via the `f` argument provided to the callback inside `fake()`: `fake(f => f.name.firstName())`.","cause":"Trying to directly access `faker` methods outside of the `fake()` helper function, or without passing the `f` argument.","error":"ReferenceError: faker is not defined"},{"fix":"Verify that your `fake()` callback receives the `faker` instance as an argument (`fake(f => ...)`) and that the `faker.js` method you are calling (e.g., `f.name.findName()`) exists in the `faker.js` API.","cause":"This error often occurs within the `fake()` callback if the `f` (faker) object is not passed or if an invalid `faker.js` method is called.","error":"TypeError: Cannot read properties of undefined (reading 'someMethod')"}],"ecosystem":"npm"}