Skip to content

Commit

Permalink
Merge pull request #3 from roalcantara/fix-factory-extend-method
Browse files Browse the repository at this point in the history
Fix the factory's extend method
  • Loading branch information
roalcantara authored Aug 7, 2018
2 parents 3b50a35 + 48167b9 commit 5f6ba39
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<a name="0.1.4"></a>
## [0.1.4](https://github.com/roalcantara/factory-bot-ts/compare/v0.1.3...v0.1.4) (2018-08-07)
<a name="0.1.5"></a>
## [0.1.5](https://github.com/roalcantara/factory-bot-ts/compare/v0.1.4...v0.1.5) (2018-08-07)


### Bug Fixes

* **factories:** Fix extend method ([e53905d](https://github.com/roalcantara/factory-bot-ts/commit/e53905d))
* **factories:** Fix the clear method ([4d96588](https://github.com/roalcantara/factory-bot-ts/commit/4d96588))
* **factories:** Fix the count method ([9b29a62](https://github.com/roalcantara/factory-bot-ts/commit/9b29a62))
* **factories:** Require partial attributes ([22f55c6](https://github.com/roalcantara/factory-bot-ts/commit/22f55c6))
* **release:** Add dist folder ([8754133](https://github.com/roalcantara/factory-bot-ts/commit/8754133))
* **release:** Update dist folder ([a237927](https://github.com/roalcantara/factory-bot-ts/commit/a237927))
* **release:** Update dist folder ([40f15f8](https://github.com/roalcantara/factory-bot-ts/commit/40f15f8))


### Features
Expand Down
10 changes: 9 additions & 1 deletion dist/factory-bot.js

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

2 changes: 1 addition & 1 deletion dist/factory-bot.js.map

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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "factory-bot-ts",
"version": "0.1.4",
"version": "0.1.5",
"description": "A simple library for setting up TypeScript objects as test data - heavily inspired by the awesome Ruby's factory_bot",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/factory-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class FactoryBot {
if (!this.has(name)) throw new Error(`Factory '${name}' has not been defined!`)
if (this.has(trait)) throw new Error(`Factory '${name}'\`s trait '${trait}' has already been defined!`)

this.factories[trait] = this.factories[name]
this.factories[trait] = { ...this.factories[name] }

this.factories[trait].attributes = Object.assign({},
...this.factories[name].attributes, attributes
Expand Down
14 changes: 14 additions & 0 deletions tests/factory-bot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ describe('FactoryBot', () => {
FactoryBot.extend<Ninja>('ninja', 'jōnin', {
level: NinjaRank.JONIN
})

FactoryBot.extend<Ninja>('ninja', 'chuunin:sensor', {
level: NinjaRank.CHUUNIN,
sensor: true
})
})

it('extends existing factories in order to generate specialized data', () => {
Expand All @@ -281,6 +286,15 @@ describe('FactoryBot', () => {
level: NinjaRank.JONIN,
sensor: false
}))

expect(FactoryBot.build<Ninja>('chuunin:sensor')).to.deep
.eq(new Ninja({
id: 1,
name: 'Kakashi Hatake',
username: 'kakashi',
level: NinjaRank.CHUUNIN,
sensor: true
}))
})

context('when the trait already exists', () => {
Expand Down

0 comments on commit 5f6ba39

Please sign in to comment.