test-data-bot
Advanced tools
Comparing version 0.6.1 to 0.7.0
@@ -0,1 +1,6 @@ | ||
### 0.7.0 [24 Jan] 2019 | ||
- Fix a bug where you were unable to pass plain functions in as values to builders | ||
- Fix `arrayOf` behaviour so it can take a builder and correctly call it. | ||
### 0.6.1 [01 Dec] 2018 | ||
@@ -2,0 +7,0 @@ |
{ | ||
"name": "test-data-bot", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "Generate test data for your tests easily.", | ||
@@ -10,3 +10,4 @@ "engines": { | ||
"scripts": { | ||
"test": "jest" | ||
"test": "yarn run lint && jest", | ||
"lint": "eslint 'src/*.js' && prettier --list-different 'src/*.js'" | ||
}, | ||
@@ -22,9 +23,9 @@ "keywords": [ | ||
"devDependencies": { | ||
"eslint": "4.19.1", | ||
"eslint-config-prettier": "3.3.0", | ||
"eslint": "5.12.1", | ||
"eslint-config-prettier": "3.6.0", | ||
"eslint-config-unobtrusive": "1.2.2", | ||
"eslint-plugin-jest": "21.17.0", | ||
"eslint-plugin-prettier": "2.6.0", | ||
"jest": "23.1.0", | ||
"prettier": "1.15.3" | ||
"eslint-plugin-jest": "22.1.3", | ||
"eslint-plugin-prettier": "3.0.1", | ||
"jest": "23.6.0", | ||
"prettier": "1.16.1" | ||
}, | ||
@@ -31,0 +32,0 @@ "dependencies": { |
@@ -16,4 +16,2 @@ class Generator { | ||
return value() | ||
} else if (typeof value === 'function') { | ||
return this.fullyExpandReturn(value(), nextSequence) | ||
} else if (typeof value === 'object') { | ||
@@ -25,2 +23,4 @@ return Object.keys(value).reduce((newObj, currentKey) => { | ||
}, {}) | ||
} else if (typeof value === 'function') { | ||
return value | ||
} else { | ||
@@ -60,2 +60,7 @@ return value | ||
}) | ||
} else if ( | ||
typeof this.data.builder === 'function' && | ||
this.data.builder.name === 'builderFuncToReturn' | ||
) { | ||
return this.data.builder() | ||
} else { | ||
@@ -62,0 +67,0 @@ return this.data.builder |
@@ -145,3 +145,3 @@ const { | ||
friends: arrayOf(fake(f => f.name.findName()), 2), | ||
comments: arrayOf(commentBuilder(), 3), | ||
comments: arrayOf(commentBuilder, 3), | ||
}) | ||
@@ -156,2 +156,5 @@ | ||
) | ||
expect(user.friends[0]).not.toEqual(user.friends[1]) | ||
expect(user.comments[0]).not.toEqual(user.comments[1]) | ||
}) | ||
@@ -258,2 +261,47 @@ | ||
}) | ||
it('lets you pass a plain old function', () => { | ||
const userBuilder = build('User').fields({ | ||
isAdmin: () => false, | ||
}) | ||
const user = userBuilder() | ||
expect(user.isAdmin()).toEqual(false) | ||
}) | ||
it('lets you return a function from perBuild', () => { | ||
const userBuilder = build('User').fields({ | ||
isAdmin: perBuild(() => jest.fn().mockImplementation(() => false)), | ||
}) | ||
const user = userBuilder() | ||
expect(user.isAdmin()).toEqual(false) | ||
}) | ||
it('lets you define nested builders', () => { | ||
const imageBuilder = build('image').fields({ | ||
original: fake(f => f.image.imageUrl()), | ||
slug: fake(f => f.lorem.slug()), | ||
}) | ||
const userBuilder = build('User').fields({ | ||
isAdmin: perBuild(() => jest.fn().mockImplementation(() => false)), | ||
images: arrayOf(imageBuilder, 3), | ||
}) | ||
const user = userBuilder() | ||
expect(user.images.length).toEqual(3) | ||
expect(user.images.map(i => i.original)).toEqual([ | ||
expect.any(String), | ||
expect.any(String), | ||
expect.any(String), | ||
]) | ||
expect(user.images.map(i => i.slug)).toEqual([ | ||
expect.any(String), | ||
expect.any(String), | ||
expect.any(String), | ||
]) | ||
expect( | ||
(user.images[0].slug !== user.images[1].slug) !== user.images[2].slug | ||
).toEqual(true) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
179052
428