-
Hey, I'm really unsure how to go about constructing an arbitrary which can model the following interface:
An example model of this interface could be:
Ideally I would like to write the following:
So the immediate issues I encounter is that I would like to use the countryCodeArb as a symbol for the first record entry, which I can't. I feel that I'm very limited in how I can actually use fast-check to construct records, but maybe I'm not using the library correctly? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You may try something like: function fakerToArb(fakerGen) {
return fc
.integer()
.noBias()
.noShrink()
.map(seed => {
faker.seed(seed);
return fakerGen();
});
}
const countryCodeArb = fakerToArb(faker.address.countryCode);
const countrySettingsArb = fc.uniqueArray(
fc.record({ code: countryCodeArb, active: fc.boolean() }),
{ minLength: 1, selector: country => country.code },
)
.map(countries => {
return {
default: countries[0].code,
...Object.fromEntries(
countries.map((country, index) => [country.code, { order: index, active: country.active }])
)
};
}); |
Beta Was this translation helpful? Give feedback.
You may try something like: