Replies: 2 comments 5 replies
-
Hey :), kind of the same problem https://discord.com/channels/929487054990110771/929487054990110779/973169629725851668 Current possible solutions, https://discord.com/channels/929487054990110771/929487054990110779/973350813260984320 and https://discord.com/channels/929487054990110771/929487054990110779/973351060976586792 We will try to discuss this behavior in our faker meeting :) |
Beta Was this translation helpful? Give feedback.
-
Just to give you a hint why there is no easy solution to this, please have a look at this example. const person = {
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
} Now, lets introduce a middleName: const person = {
firstName: faker.name.firstName(),
middleName: faker.name.firstName(),
lastName: faker.name.lastName(),
} Sure enough, the last name changes unexpectedly. So lets assume, we fix faker to handle the lastName method independently from the rest. So now lets assume that - for whatever reason - the firstName and the middleName generation get swapped. const middleName = faker.name.firstName();
const person = {
firstName: faker.name.firstName(),
middleName,
middleNameAbbr: middleName.substring(0, 1) + '.',
lastName: faker.name.lastName(),
} So the firstName and the middleName both have changed and we all know why, its just something we dont really want. So what is the solution? faker1.seed(seed + 1337);
faker2.seed(seed + 2022);
faker3.seed(seed + 42);
const person = {
firstName: faker1.name.firstName(),
middleName: faker2.name.firstName(),
lastName: faker3.name.lastName(),
} Or faker.seed(seed + 1337);
const firstName = ...;
faker.seed(seed + 2022);
const middleName = ...;
faker.seed(seed + 42);
const lastName = ...; (the magic numbers here are used as randomizers, so firstName and middleName are different from each other) Now, you can add, rearange or remove methods as you like. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Please help understand behaviour of
name.firstName
in general, observed when in sequence ofname.firstName()
I insert new usage ofname.lastName()
the result of followingname.firstName()
sequence results starts to differ:Which seems to be a problem for example in tests if I decide write assertion against "Jermaine" text string, but later extend my model somewhere in the middle. This observation makes me thing that I can't assert to actual string values?
Code sandbox to try it out https://codesandbox.io/s/faker-forked-75kozx?file=/src/index.js
Beta Was this translation helpful? Give feedback.
All reactions