Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fishery

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fishery

A library for setting up JavaScript factories to help build objects as test data, with full TypeScript support

  • 2.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
250K
increased by5.79%
Maintainers
1
Weekly downloads
 
Created

What is fishery?

Fishery is a JavaScript library for creating test data. It allows you to define factories for your data models, making it easy to generate consistent and realistic test data for your applications.

What are fishery's main functionalities?

Defining a Factory

This feature allows you to define a factory for a data model. In this example, a factory for a user model is defined with an id, name, and email. The `sequence` function ensures that each generated user has a unique id and email.

const { Factory } = require('fishery');

const userFactory = Factory.define(({ sequence }) => ({
  id: sequence,
  name: `User ${sequence}`,
  email: `user${sequence}@example.com`
}));

const user = userFactory.build();
console.log(user);

Building Multiple Instances

This feature allows you to generate multiple instances of a model. In this example, three user instances are generated using the `buildList` method.

const users = userFactory.buildList(3);
console.log(users);

Customizing Instances

This feature allows you to customize the generated instances. In this example, a user instance is generated with a custom name while other attributes are generated by the factory.

const customUser = userFactory.build({ name: 'Custom User' });
console.log(customUser);

Associations

This feature allows you to define associations between different models. In this example, a post model is defined with an associated user model as the author.

const postFactory = Factory.define(({ sequence }) => ({
  id: sequence,
  title: `Post ${sequence}`,
  author: userFactory.build()
}));

const post = postFactory.build();
console.log(post);

Other packages similar to fishery

Keywords

FAQs

Package last updated on 04 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc