New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

factory-mate

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

factory-mate - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

dist/factoryMate/generators/Generator.d.ts

1

dist/index.d.ts
export * from './factoryMate/FactoryMateAware';
export * from './factoryMate/FactoryMate';
export * from './factoryMate/generators/NumberGenerator';

@@ -8,1 +8,2 @@ "use strict";

__export(require("./factoryMate/FactoryMate"));
__export(require("./factoryMate/generators/NumberGenerator"));

8

package.json
{
"name": "factory-mate",
"version": "1.0.2",
"version": "1.1.0",
"description": "TypeScript library for building domain objects",

@@ -9,3 +9,7 @@ "keywords": [

"factory",
"builder"
"builder",
"tdd",
"bdd",
"test",
"fixture"
],

@@ -12,0 +16,0 @@ "main": "./dist/index.js",

# FactoryMate
[![Build Status](https://travis-ci.org/rwaskiewicz/factory-mate.svg?branch=develop)](https://travis-ci.org/rwaskiewicz/factory-mate)
[![npm version](https://badge.fury.io/js/factory-mate.svg)](https://badge.fury.io/js/factory-mate)

@@ -86,2 +87,49 @@ FactoryMate is a TypeScript-based fixture library for instantiating domain objects for testing purposes, inspired by

### Sequence Generation
FactoryMate supports numerical sequence generation via the ```NumberGenerator``` class. This can be helpful for the purposes of generating ID values for domain objects to better represent real world scenarios (e.g. keys in from a datastore)
In order to add sequential generation support to an entity, it can be imported into it's factory as such:
``` typescript
import { FactoryMate, FactoryMateAware } from 'factory-mate';
import { NumberGenerator } from 'factory-mate';
import { GroceryItem } from './GroceryItem';
@FactoryMateAware
export class GroceryItemFactory {
public define() {
// Defines the NumberGenerator instance to be used across all calls to FactoryMate.build(GroceryItem.name);
const numberGenerator = new NumberGenerator();
FactoryMate.define(GroceryItem, (): GroceryItem => {
const groceryItem = new GroceryItem();
// The nextValue() method retrieves the next value in the sequence
groceryItem.id = numberGenerator.nextValue();
groceryItem.groceryName = 'chewy cookies';
return groceryItem;
});
}
}
```
Using the factory method above, three sequential calls to ```FactoryMate.build(GroceryItem.name)``` will result in the following:
``` typescript
const groceryItem1: GroceryItem = FactoryMate.build(GroceryItem.name);
const groceryItem2: GroceryItem = FactoryMate.build(GroceryItem.name);
const groceryItem3: GroceryItem = FactoryMate.build(GroceryItem.name);
console.log(JSON.stringify(groceryItem1)); //'{"id":1,"groceryName":"chewy cookies"}'
console.log(JSON.stringify(groceryItem2)); //'{"id":2,"groceryName":"chewy cookies"}'
console.log(JSON.stringify(groceryItem3)); //'{"id":3,"groceryName":"chewy cookies"}'
```
#### Changing sequence values
By default, ```NumberGenerator``` starts at a value of 1 and increments by 1. These values can be altered at instantiation time if desired
``` typescript
// Start at one, increment by one: 1, 2, 3 ...
const numberGenerator = new NumberGenerator();
// Start at one, increment by two: 1, 3, 5 ...
const numberGenerator = new NumberGenerator(1, 2);
// Start at zero, increment by one: 0, 1, 2, ...
const numberGenerator = new NumberGenerator(0);
```
## Example

@@ -88,0 +136,0 @@ An example project using FactoryMate can be found here [FactoryMateConsumer](https://github.com/rwaskiewicz/factory-mate-consumer)

Sorry, the diff of this file is not supported yet

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