Skip to content

Commit

Permalink
Merge branch 'master' into before-after-generate
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsJonQ committed Nov 16, 2017
2 parents 40d7523 + 786aaf9 commit 06a1b7a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/api/derived.md
Expand Up @@ -21,7 +21,7 @@ To have more control over your computed values, you can use the `derived` functi
### Example

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

const Spec = createSpec({
fname: faker.name.firstName(), // Alice
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "@helpscout/helix",
"private": false,
"version": "0.0.11",
"version": "0.0.12",
"description": "A Faker-powered fixture generator for Javascript",
"main": "lib/index.js",
"module": "lib/index.es.js",
Expand Down
7 changes: 3 additions & 4 deletions src/HelixSpec/index.js
Expand Up @@ -41,8 +41,8 @@ class HelixSpec {
return this
}

generate (count = 0, max) {
if (!isNumber(count)) {
generate (count, max) {
if (!isNumber(count) && count !== undefined) {
throw Exception('HelixSpec.generate()', 'Argument must be a valid number.')
}
if (max !== undefined) {
Expand All @@ -55,8 +55,7 @@ class HelixSpec {
count = faker.random.number({min: count, max})
}

// If count was 0, max was specified, but the randomized count comes back 0, return []
const isArray = count || max !== undefined
const isArray = isNumber(count)
const generatedSpecs = isArray
? [...Array(count)].map(() => {
// Respect seed value for multi-generated specs
Expand Down
13 changes: 11 additions & 2 deletions src/HelixSpec/tests/generate.test.js
Expand Up @@ -48,10 +48,10 @@ test('Throw if max argument is less than count argument', () => {
})

test('Generates fixtures from a spec object', () => {
const person = new HelixSpec({
const Person = new HelixSpec({
id: faker.random.number()
})
const fixture = person.generate()
const fixture = Person.generate()

expect(fixture.id).toBeTruthy()
})
Expand All @@ -70,6 +70,15 @@ test('Can generate multiple specs', () => {
expect(fixture[0].id).not.toBe(fixture[1].id)
})

test('Creates an empty array if we call generate(0)', () => {
const Person = new HelixSpec({
id: faker.random.number()
})

const fixture = Person.generate(0)
expect(fixture).toEqual([])
})

test('Can generate nested un-generated spec', () => {
const PersonSpec = new HelixSpec({
id: faker.random.number(),
Expand Down

0 comments on commit 06a1b7a

Please sign in to comment.