Mockmate — TypeScript-first mock data generator
Source: Dev.to
Introduction
Mockmate is a lightweight, TypeScript‑first library for generating mock data with a clean and flexible API. It’s designed for developers who want fast mock generation, strong typing, and zero boilerplate — whether you’re prototyping, testing, or building demos.
When working on frontend or backend applications, you often need mock data that is:
- Predictable
- Typed
- Easy to extend
- Quick to generate
Mockmate focuses on exactly that.
Installation
npm install @mockmate/mockmate
# or
yarn add @mockmate/mockmate
# or
pnpm add @mockmate/mockmate
Basic Usage
import { mockmate } from '@mockmate/mockmate';
const users = await mockmate({
category: 'users',
quantity: 2,
});
console.log(users);
Selecting Specific Fields
const users = await mockmate({
category: 'users',
quantity: 3,
pick: ['id', 'name', 'email'],
});
Extending with Custom Fields
const users = await mockmate({
category: 'users',
quantity: 2,
extend: {
isActive: () => true,
createdAt: () => new Date().toISOString(),
},
});
Error Handling
Mockmate uses custom error classes for predictable error handling:
try {
await mockmate({ category: 'unknown' });
} catch (error) {
console.error(error);
}
TypeScript Support
Mockmate is built with TypeScript from the ground up, providing full type safety out of the box.
Planned Features
- Additional categories and data generators
- Advanced customization options
- Integration helpers for popular testing frameworks
License
Mockmate is open‑source and MIT licensed.
- GitHub:
- npm:
Final Thoughts
If you’re tired of overcomplicated mock generators and want something simple, typed, and modern — give Mockmate a try.
Happy coding 👋