JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1079
  • Score
    100M100P100Q124038F
  • License MIT

A Faker-powered fixture generator for Javascript

Package Exports

  • @helpscout/helix

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@helpscout/helix) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Helix 💠 Build Status Coverage Status npm version

A Faker-powered fixture generator for Javascript.

Helix allows you to quickly (and reliably) generate fixture data to be hydrated into Javascript components/views (like React, Vue, Backbone, etc…).

Install

npm install @helpscout/helix --save-dev

Getting started

To get started, install Helix by entering the npm install command above (or use yarn add).

Next, import both createSpec and faker from Helix to the file in your project.

import { createSpec, faker } from '@helpscout/helix'

Example

The createSpec function is used to define your fixture spec. Helix comes with an adjusted version of Faker.js, which also needs to be imported. Note, the API for Helix's faker is the exact same as Faker.js.

const CustomerSpec = createSpec({
  id: faker.random.number()
  fname: faker.name.firstName()
  lname: faker.name.lastName()
  company: faker.company.companyName()
})

const fixture = CustomerSpec.generate()

// Output
// {
//   id: 12339041,
//   fname: 'Alice',
//   lname: 'Konigsberg',
//   company: 'Smiths Co.'
// }

For a full list of Faker methods, check out their documentation.

Seeding

Seeding allows you to consistently generate the same data based on a specific seed number.

To seed your Spec, use the .seed() method just before .generate().

const CustomerSpec = createSpec({
  id: faker.random.number()
  fname: faker.name.firstName()
  lname: faker.name.firstName()
  company: faker.company.companyName()
})

// Seeding with "12"
const fixture = CustomerSpec.seed(12).generate()

Multi-generation

You can generate multiple instances of your Spec fixture using the generate() method. All you have to do is pass in the number of instances you want generated!

const Text = createSpec({
  id: faker.random.number(),
  message: faker.lorem.paragraph()
})

const fixture = Text.generate(5)

// Output
// [{}, {}, {}, {}, {}]

Seeding

To seed multi-generated fixtures, simply use the .seed() method before generating.

const Text = createSpec({
  id: faker.random.number(),
  message: faker.lorem.paragraph()
})

const fixture = Text.seed(50).generate(5)

Note: Seed values aren't passed down from the parent Spec to children multi-specs.

Nesting

Specs can be nested! In the example below, you can see that we've created 2 Specs: MessageSpec and ConvoSpec. Our ConvoSpec contains MessageSpec inside.

const MessageSpec = createSpec({
  id: faker.random.number(),
  read: faker.random.boolean(),
  message: faker.lorem.paragraph()
})

const ConvoSpec = createSpec({
  id: faker.random.number(),
  messages: MessageSpec.generate(5)
})

const fixture = ConvoSpec.generate()

// Output
// {
//   id: 12341,
//   messages: [{}, {}, {}, {}, {}]
// }

TODO

  • Computed Faker values
  • Extend/override generated specs