Releases: thoughtbot/fishery
2.2.2
2.2.1
2.1.0
2.0.0
1.4.0
1.3.1
1.3.0
Bugfix: Fix merge behavior of arrays
Fixes a bug where building a factory with an empty array was not overriding a non-empty array if it was defined that way in a factory:
const elementsFactory = Factory.define<Elements>(() => ({
elements: ["STRING"],
}));
elementsFactory.build({ elements: [] }));
// { elements: ["STRING"] }
Now, when passing an array to myFactory.build()
, that array fully overrides the object defined in the factory. There is no partial/deep merging of arrays. The typing of params
in the factory now also reflect this. This should not be an issue for most users, as the existing merging of arrays was not documented and did not behave as most would expect.
See #38 for more information.
Rename afterCreate to afterBuild, remove factory registration requirement
This release includes three breaking changes. Updating your code should be fairly mechanical using the guide below:
afterCreate
renamed to afterBuild
As the heading suggests, the afterCreate
function that can be accessed in factories and the afterCreate
factory extension function have been renamed to afterBuild
(PR). To update your code, just replace all instances of afterCreate
with afterBuild
like shown below:
- Factory.define(({ afterCreate }) => { ... })
+ Factory.define(({ afterBuild }) => { ... })
- myFactory.afterCreate(object => { ... })
+ myFactory.afterBuild(object => { ... })
Removed unnecessary factories
registration and injection
Fishery no longer requires (or provides a mechanism for) users to register their factories together, and factory definitions no longer take a Factories
type parameter or accept a factories
argument. For more info on this change, see the PR.
To update your code, make the following changes:
Remove register
call
- const factories = register({ myFactory, myOtherFactory })
+ const factories = { myFactory, myOtherFactory }
Replace defineUnregistered
with define
Since factory registration is no longer required, there is no longer a concept of "unregistered" factories. Just use define
.
- Factory.defineUnregistered(...)
+ Factory.define(...)
Remove second type parameter from Factory.define
and any uses of factories
in the factory
If you need to use another factory in your factory, just import it directly. For more info, see the readme.
- Factory.define<User, Factories, UserTransientParams(({ factories }) => { ... })
+ Factory.define<User, UserTransientParams(() => { ... }_
Sequences now start at 1 instead of 0
Sequences now start at 1 instead of 0. A factory.rewindSequence()
function was also added that resets the factory's sequence
counter back to 1.
Factory extension and traits API
This adds mechanisms for extending factories and adding convenience methods to factories to simplify building complex objects. For more information, see the PR where this was implemented.