@luxuryescapes/lib-factories
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

lib-factories

Create a factories.js:

const { define, build } = require('lib-factories');

define("myObject", ({ counter, uuid }) => ({
  id: uuid(),
  counter: counter(),
  items: []
}))

define("myChildObject", ({ uuid }) => ({
  id: uuid(),
  price: 9.50
}))

module.exports = { build }

Then require in tests:

const { build } = require('./factories');

const collection = [
  build("myObject", {
    items: [
      build("myChildObject", {
        price: 12.5
      })
    ]
  }),
  build("myObject", {
    items: [
      build("myChildObject", {
        price: 10
      })
    ]
  })
];

Generates:

[
  {
    "id": "fe37c324-589b-42e3-a231-da7f66faa114",
    "counter": 1,
    "items": [
      {
        "id": "3947b9ec-e375-443a-8bd9-c3c7a9fd51db",
        "price": 12.5
      }
    ]
  },
  {
    "id": "77b64f00-0f1f-4383-9d8a-2e206f857dc4",
    "counter": 2,
    "items": [
      {
        "id": "5dedf786-eeee-44a4-b250-5ed6a4d668b5",
        "price": 10
      }
    ]
  }
]

Running tests

yarn test

Release

Use npm to patch, minor or whatever version:

npm version patch -m "release version %s"
git push && git push --tags

https://docs.npmjs.com/cli/version

Readme

Keywords

none

Package Sidebar

Install

npm i @luxuryescapes/lib-factories

Weekly Downloads

709

Version

1.0.5

License

ISC

Unpacked Size

4.82 kB

Total Files

12

Last publish

Collaborators

  • emanuel.kozerski
  • elias.vieira
  • roberto-luxuryescapes
  • angus-leung
  • ethanscavia
  • jahanzeb-hussain-le
  • lukejudd-lux
  • chiamaka-ibeme-le
  • vincent-tran-le
  • welingtonlarsenlux
  • hfrankel
  • sangin.lee
  • tuanhung-pham-le
  • lukas-zimmermann-le
  • alexanderswanle
  • lux-alexd
  • william.idoine
  • edward.iskenderian
  • adham-oliveira
  • james-kwok-le
  • aleksandar.vuksanovic
  • nishanthi.n
  • glesage_le
  • daviaazevedo
  • william-ong
  • philippecarvalho
  • dulaj.pathirana
  • hamed.le
  • samhammond
  • paulo.silva3991
  • noahxny
  • dishang
  • ahmad.hafez
  • jordikitto_le
  • steve.dang
  • andrewjohnstone
  • brunohaveroth
  • pavel-lux
  • mary-le
  • pankaj-le
  • rubenbelem
  • gabe-miranda-lux
  • thilina-piyadasun-le
  • gabriel.costa.lux
  • icelic
  • cervantes.kenneth
  • harish-indla-le
  • eran.stiller.luxury.escapes
  • sakethgetla
  • nicholaspuglia
  • sitaraman
  • siddharth.bose
  • aarontoomey-le
  • sergio.costa.luxuryescapes
  • mzilio-lux
  • michael-reid-le
  • matthewdelaneyatluxuryescapes
  • ricardobalbinot
  • callmekev
  • semeer-acheerithodi-le
  • andrey-tryapitsin-le
  • quan.tang
  • alexander.yakovenko
  • greg-cumming-le
  • jerry.huang-le
  • dan-wanigasekera-le
  • dunedayl
  • arminmon-le
  • mattswansonlux
  • cleberricardi
  • felipefeal.lux
  • tracymu
  • chris.nguyen.lux
  • marhalpert
  • reb2020
  • zediah
  • sonyque
  • joshuacullenlux
  • shawn-cx-li
  • colins44
  • diegogadens
  • felixivanov
  • joshua.paling.le
  • operations.luxgroup
  • eddiemcleanlux
  • robert.harris.lux
  • kostya-luxuryescapes
  • alexb.pi
  • kaustuva
  • luizcarraro
  • ryan.tian
  • le_tyang
  • richardbiddle
  • henryshen-le
  • jamesly