You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to base the value in the derived factory on the value that was built by the original factory, but looks like this isn't possible with withDerivation or withDerivation1? (I attached an example below)
Is there any other way to achieve this? If not, would you consider adding this functionality into the library?
Example
import*asFactoryfrom"factory.ts";constuserFactory=Factory.makeFactory({firstName: "Peter",lastName: "Parker"});// Doesn't work - firstName is an empty objectconstuserWithMiddleNameFactory=userFactory.withDerivation('firstName',(user)=>{returnuser.firstName+" Benjamin"});// Also doesn't workconstaltUserWithMiddleNameFactory=userFactory.withDerivation1(['firstName'],'firstName',(firstName)=>{returnfirstName+" Benjamin"});// Works for different fieldsconstuserWithSameNamesFactory=userFactory.withDerivation('firstName',(user)=>{returnuser.lastName});console.table({userWithMiddleNameFactory: userWithMiddleNameFactory.build(),altUserWithMiddleNameFactory: altUserWithMiddleNameFactory.build(),userWithSameNamesFactory: userWithSameNamesFactory.build()});
Hello! 👋
I'm trying to base the value in the derived factory on the value that was built by the original factory, but looks like this isn't possible with
withDerivation
orwithDerivation1
? (I attached an example below)Is there any other way to achieve this? If not, would you consider adding this functionality into the library?
Example
which prints:
p.s. This library has been super useful, thanks a lot for making it! 👏
The text was updated successfully, but these errors were encountered: