Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

faker.name lastName and middleName doesn't work correctly with gender selection #373

Closed
Shinigami92 opened this issue Jan 30, 2022 · 3 comments · Fixed by #440
Closed

faker.name lastName and middleName doesn't work correctly with gender selection #373

Shinigami92 opened this issue Jan 30, 2022 · 3 comments · Fixed by #440
Assignees
Labels
c: bug Something isn't working

Comments

@Shinigami92
Copy link
Member

Describe the bug

When using faker.name.lastName or faker.name.middleName with a specific gender, it returns invalid behavior.
It will return female names for male names.

Reproduction

faker.locale = 'uk';

const name = faker.name.middleName(0);
expect(faker.definitions.name.male_middle_name).toContain(name); // returns a female name

Additional Info

faker/src/name.ts

Lines 63 to 125 in 730ca6a

/**
* lastName
*
* @method lastName
* @param gender
* @memberof faker.name
*/
lastName(gender?: string | number): string {
if (
typeof this.faker.definitions.name.male_last_name !== 'undefined' &&
typeof this.faker.definitions.name.female_last_name !== 'undefined'
) {
// some locale datasets ( like ru ) have last_name split by gender. i have no idea how last names can have genders, but also i do not speak russian
// see above comment of firstName method
if (typeof gender !== 'number') {
gender = this.faker.datatype.number(1);
}
if (gender === 0) {
return this.faker.random.arrayElement(
this.faker.locales[this.faker.locale].name.male_last_name
);
} else {
return this.faker.random.arrayElement(
this.faker.locales[this.faker.locale].name.female_last_name
);
}
}
return this.faker.random.arrayElement(
this.faker.definitions.name.last_name
);
}
/**
* middleName
*
* @method middleName
* @param gender
* @memberof faker.name
*/
middleName(gender?: string | number): string {
if (
typeof this.faker.definitions.name.male_middle_name !== 'undefined' &&
typeof this.faker.definitions.name.female_middle_name !== 'undefined'
) {
if (typeof gender !== 'number') {
gender = this.faker.datatype.number(1);
}
if (gender === 0) {
return this.faker.random.arrayElement(
this.faker.locales[this.faker.locale].name.male_middle_name
);
} else {
return this.faker.random.arrayElement(
this.faker.locales[this.faker.locale].name.female_middle_name
);
}
}
return this.faker.random.arrayElement(
this.faker.definitions.name.middle_name
);
}

@Shinigami92 Shinigami92 added the s: pending triage Pending Triage label Jan 30, 2022
@Shinigami92 Shinigami92 added this to the v6.1 - First bugfixes milestone Jan 30, 2022
@Shinigami92 Shinigami92 added the c: bug Something isn't working label Jan 30, 2022
@github-actions github-actions bot removed the s: pending triage Pending Triage label Jan 30, 2022
@wael-fadlallah
Copy link
Contributor

wael-fadlallah commented Feb 2, 2022

In Arabic Locale there are also a strange behavior

const faker = require("./faker/dist/cjs/locale/ar");

console.log(faker.name.middleName()); // return letters a, b, c ...etc

@wael-fadlallah
Copy link
Contributor

It seems the same behavior exists in English

ganeshbudhathoki added a commit to ganeshbudhathoki/faker that referenced this issue Feb 5, 2022
@ganeshbudhathoki
Copy link
Contributor

fix for default (en) locale, locale (uk) is working as expected.
PR: #440

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants