-
I feel that this is such a basic thing that it might have been documented or answered already but I can't for the love of god find anything. What I do ... or try to do: I generate records containing multiple fields. But two fields need the exact same random string because they need to be matched through the code. Take this extremely simplified and probably stupid example:
I need to generate this RANDOM_STRING once but use the one generated value at two places. I tried to do
und put the randomString const where I need that value but Thanks for help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Option 1: not my recommendation as export const buildArbitraryObject = (): fc.Arbitrary<MyType> => {
return fc.string().chain(s => fc.record<MyType>({
key: s,
value: fc.record<SubType>({
something: s
})
})),
} Option 2: with export const buildArbitraryObject = (): fc.Arbitrary<MyType> => {
return fc.record({
key: s,
value: fc.record({ // value without the something part
})
})).map(o => ({...o, value: {...o.value, something: o.key}})),
} Option 3: I have to think a way to simplify the construction of such arbitrary to have something as simple as Disclaimer: answered from my phone |
Beta Was this translation helpful? Give feedback.
Option 1: not my recommendation as
chain
tend to shrink badlyOption 2: with
map
Option 3: I have to think a way to simplify the construction of such arbitrary to have something as simple as
chain
version (or even simpler) but with the shrink capacities ofmap
Disclai…