diff --git a/src/definitions/person.ts b/src/definitions/person.ts index c761b9a38ba..9ae488a60c2 100644 --- a/src/definitions/person.ts +++ b/src/definitions/person.ts @@ -1,15 +1,30 @@ import type { LocaleEntry } from './definitions'; +/** + * Entries that are dependent on a person's sex. + */ export type PersonEntryDefinition = | { + /** + * Values that are primarily attributable to only females. + */ + female: T[]; + /** + * Values that cannot clearly be attributed to a specific sex or are used for both sexes. + */ generic?: T[]; + /** + * Values that are primarily attributable to only males. + */ male: T[]; - female: T[]; } | { + female?: never; + /** + * Values that cannot clearly be attributed to a specific sex or are used for both sexes. + */ generic: T[]; male?: never; - female?: never; }; type SimplePersonEntryDefinition = PersonEntryDefinition; diff --git a/src/modules/person/index.ts b/src/modules/person/index.ts index 4baf1274769..85154c35ff9 100644 --- a/src/modules/person/index.ts +++ b/src/modules/person/index.ts @@ -2,11 +2,27 @@ import type { Faker } from '../..'; import type { PersonEntryDefinition } from '../../definitions/person'; import { ModuleBase } from '../../internal/module-base'; +/** + * The enum for values corresponding to a person's sex. + */ export enum Sex { + /** + * Is used for values that are primarily attributable to only females. + */ Female = 'female', + /** + * Is used for values that cannot clearly be attributed to a specific sex or are used for both sexes. + */ + Generic = 'generic', + /** + * Is used for values that are primarily attributable to only males. + */ Male = 'male', } +/** + * The parameter type for values corresponding to a person's sex. + */ export type SexType = `${Sex}`; /** @@ -20,30 +36,48 @@ export type SexType = `${Sex}`; */ function selectDefinition( faker: Faker, - sex: SexType | undefined, + sex: SexType = faker.person.sexType(), personEntry: PersonEntryDefinition ): T[] { const { generic, female, male } = personEntry; - switch (sex) { - case Sex.Female: { - return female ?? generic; - } - case Sex.Male: { - return male ?? generic; - } + if (sex === 'generic') { + return ( + generic ?? + faker.helpers.arrayElement([female, male]) ?? + // The last statement should never happen at run time. At this point in time, + // the entry will satisfy at least (generic || (female && male)). + // TS is not able to infer the type correctly. + [] + ); + } - default: { - return ( - generic ?? - faker.helpers.arrayElement([female, male]) ?? - // The last statement should never happen at run time. At this point in time, - // the entry will satisfy at least (generic || (female && male)). - // TS is not able to infer the type correctly. - [] - ); + const binary = sex === 'female' ? female : male; + + if (binary != null) { + if (generic != null) { + return faker.helpers.weightedArrayElement([ + { + weight: 3 * Math.sqrt(binary.length), + value: binary, + }, + { + weight: Math.sqrt(generic.length), + value: generic, + }, + ]); } + + return binary; } + + return ( + generic ?? + // The last statement should never happen at run time. At this point in time, + // the entry will satisfy at least (generic || (female && male)). + // TS is not able to infer the type correctly. + [] + ); } /** @@ -238,16 +272,38 @@ export class PersonModule extends ModuleBase { /** * Returns a random sex type. The `SexType` is intended to be used in parameters and conditions. * + * @param options The optional options object. + * @param options.includeGeneric Whether `'generic'` should be included in the potential outputs. + * If `false`, this method only returns `'female'` and `'male'`. + * Default is `false`. + * * @see faker.person.gender(): For generating a gender related value in forms. * @see faker.person.sex(): For generating a binary-gender value in forms. * * @example * faker.person.sexType() // Sex.Female + * faker.person.sexType({ includeGeneric: true }) // Sex.Generic * * @since 8.0.0 */ - sexType(): SexType { - return this.faker.helpers.enumValue(Sex); + sexType( + options: { + /** + * Whether `'generic'` should be included in the potential outputs. + * If `false`, this method only returns `'female'` and `'male'`. + * + * @default false + */ + includeGeneric?: boolean; + } = {} + ): SexType { + const { includeGeneric = false } = options; + + if (includeGeneric) { + return this.faker.helpers.enumValue(Sex); + } + + return this.faker.helpers.arrayElement([Sex.Female, Sex.Male]); } /** diff --git a/test/modules/__snapshots__/git.spec.ts.snap b/test/modules/__snapshots__/git.spec.ts.snap index 7ffa380e63f..e0cb73ee7a7 100644 --- a/test/modules/__snapshots__/git.spec.ts.snap +++ b/test/modules/__snapshots__/git.spec.ts.snap @@ -10,28 +10,28 @@ exports[`git > 42 > commitDate > with only string refDate 1`] = `"Tue Dec 31 08: exports[`git > 42 > commitEntry > with only Date refDate 1`] = ` "commit ead331ddf0fc4446b96d368ab4bd1d31efb62f92 -Author: Jerome Vandervort -Date: Tue Dec 31 14:20:57 2019 +1100 +Author: Suzanne.Hahn +Date: Tue Dec 31 04:42:12 2019 -1000 -    bypass bluetooth application +    copy haptic card " `; exports[`git > 42 > commitEntry > with only number refDate 1`] = ` "commit ead331ddf0fc4446b96d368ab4bd1d31efb62f92 -Author: Jerome Vandervort -Date: Tue Dec 31 14:20:57 2019 +1100 +Author: Suzanne.Hahn +Date: Tue Dec 31 04:42:12 2019 -1000 -    bypass bluetooth application +    copy haptic card " `; exports[`git > 42 > commitEntry > with only string refDate 1`] = ` "commit ead331ddf0fc4446b96d368ab4bd1d31efb62f92 -Author: Jerome Vandervort -Date: Tue Dec 31 14:20:57 2019 +1100 +Author: Suzanne.Hahn +Date: Tue Dec 31 04:42:12 2019 -1000 -    bypass bluetooth application +    copy haptic card " `; @@ -53,28 +53,28 @@ exports[`git > 1211 > commitDate > with only string refDate 1`] = `"Tue Dec 31 2 exports[`git > 1211 > commitEntry > with only Date refDate 1`] = ` "commit d4fefa7fbaec9dc4c48fa8ebf46fb7c8563cf3fa -Author: Deion Durgan -Date: Tue Dec 31 11:08:15 2019 -0600 +Author: Debbie.Kshlerin70 +Date: Tue Dec 31 20:55:12 2019 -0900 -    override solid state array +    reboot multi-byte feed " `; exports[`git > 1211 > commitEntry > with only number refDate 1`] = ` "commit d4fefa7fbaec9dc4c48fa8ebf46fb7c8563cf3fa -Author: Deion Durgan -Date: Tue Dec 31 11:08:15 2019 -0600 +Author: Debbie.Kshlerin70 +Date: Tue Dec 31 20:55:12 2019 -0900 -    override solid state array +    reboot multi-byte feed " `; exports[`git > 1211 > commitEntry > with only string refDate 1`] = ` "commit d4fefa7fbaec9dc4c48fa8ebf46fb7c8563cf3fa -Author: Deion Durgan -Date: Tue Dec 31 11:08:15 2019 -0600 +Author: Debbie.Kshlerin70 +Date: Tue Dec 31 20:55:12 2019 -0900 -    override solid state array +    reboot multi-byte feed " `; @@ -96,28 +96,28 @@ exports[`git > 1337 > commitDate > with only string refDate 1`] = `"Tue Dec 31 0 exports[`git > 1337 > commitEntry > with only Date refDate 1`] = ` "commit 36a7b5fa28d2f9bb79ca46ea394bc4f9bb0af328 -Author: Matt_Hills -Date: Tue Dec 31 00:20:42 2019 -0900 +Author: Gene_Heller +Date: Tue Dec 31 22:32:07 2019 +1200 -    synthesize wireless hard drive +    index haptic pixel " `; exports[`git > 1337 > commitEntry > with only number refDate 1`] = ` "commit 36a7b5fa28d2f9bb79ca46ea394bc4f9bb0af328 -Author: Matt_Hills -Date: Tue Dec 31 00:20:42 2019 -0900 +Author: Gene_Heller +Date: Tue Dec 31 22:32:07 2019 +1200 -    synthesize wireless hard drive +    index haptic pixel " `; exports[`git > 1337 > commitEntry > with only string refDate 1`] = ` "commit 36a7b5fa28d2f9bb79ca46ea394bc4f9bb0af328 -Author: Matt_Hills -Date: Tue Dec 31 00:20:42 2019 -0900 +Author: Gene_Heller +Date: Tue Dec 31 22:32:07 2019 +1200 -    synthesize wireless hard drive +    index haptic pixel " `; diff --git a/test/modules/__snapshots__/internet.spec.ts.snap b/test/modules/__snapshots__/internet.spec.ts.snap index 3389a20ee62..37d8c074853 100644 --- a/test/modules/__snapshots__/internet.spec.ts.snap +++ b/test/modules/__snapshots__/internet.spec.ts.snap @@ -10,7 +10,7 @@ exports[`internet > 42 > color > with greenBase option 1`] = `"#30ac5e"`; exports[`internet > 42 > color > with redBase option 1`] = `"#627a5e"`; -exports[`internet > 42 > displayName > noArgs 1`] = `"Garnet15"`; +exports[`internet > 42 > displayName > noArgs 1`] = `"Moses.Crist"`; exports[`internet > 42 > displayName > with Chinese names 1`] = `"大羽.陳95"`; @@ -22,9 +22,9 @@ exports[`internet > 42 > displayName > with accented names 1`] = `"Hélene.Müll exports[`internet > 42 > displayName > with all option 1`] = `"Jane.Doe95"`; -exports[`internet > 42 > displayName > with firstName option 1`] = `"Jane59"`; +exports[`internet > 42 > displayName > with firstName option 1`] = `"Jane15"`; -exports[`internet > 42 > displayName > with lastName option 1`] = `"Garnet_Doe"`; +exports[`internet > 42 > displayName > with lastName option 1`] = `"Moses15"`; exports[`internet > 42 > domainName 1`] = `"hospitable-unit.net"`; @@ -32,31 +32,31 @@ exports[`internet > 42 > domainSuffix 1`] = `"info"`; exports[`internet > 42 > domainWord 1`] = `"hospitable-unit"`; -exports[`internet > 42 > email > noArgs 1`] = `"Valentine.Miller15@yahoo.com"`; +exports[`internet > 42 > email > noArgs 1`] = `"Lavinia60@yahoo.com"`; exports[`internet > 42 > email > with all options 1`] = `"Jane.Doe@fakerjs.dev"`; -exports[`internet > 42 > email > with allowSpecialCharacters option 1`] = `"Valentine.Miller15@yahoo.com"`; +exports[`internet > 42 > email > with allowSpecialCharacters option 1`] = `"Lavinia60@yahoo.com"`; -exports[`internet > 42 > email > with firstName option 1`] = `"Jane.Reynolds-Miller15@yahoo.com"`; +exports[`internet > 42 > email > with firstName option 1`] = `"Jane.Miller15@yahoo.com"`; -exports[`internet > 42 > email > with lastName option 1`] = `"Valentine_Doe59@yahoo.com"`; +exports[`internet > 42 > email > with lastName option 1`] = `"Lavinia.Doe15@yahoo.com"`; -exports[`internet > 42 > email > with provider option 1`] = `"Garnet.Reynolds-Miller15@fakerjs.dev"`; +exports[`internet > 42 > email > with provider option 1`] = `"Moses.Crist@fakerjs.dev"`; exports[`internet > 42 > emoji > noArgs 1`] = `"🌾"`; exports[`internet > 42 > emoji > with options 1`] = `"🦔"`; -exports[`internet > 42 > exampleEmail > noArgs 1`] = `"Valentine.Miller15@example.com"`; +exports[`internet > 42 > exampleEmail > noArgs 1`] = `"Lavinia60@example.com"`; exports[`internet > 42 > exampleEmail > with all options 1`] = `"Jane_Doe@example.com"`; -exports[`internet > 42 > exampleEmail > with allowSpecialCharacters option 1`] = `"Valentine.Miller15@example.com"`; +exports[`internet > 42 > exampleEmail > with allowSpecialCharacters option 1`] = `"Lavinia60@example.com"`; -exports[`internet > 42 > exampleEmail > with firstName option 1`] = `"Jane.Reynolds-Miller15@example.com"`; +exports[`internet > 42 > exampleEmail > with firstName option 1`] = `"Jane.Miller15@example.com"`; -exports[`internet > 42 > exampleEmail > with lastName option 1`] = `"Valentine_Doe59@example.com"`; +exports[`internet > 42 > exampleEmail > with lastName option 1`] = `"Lavinia.Doe15@example.com"`; exports[`internet > 42 > httpMethod 1`] = `"POST"`; @@ -112,7 +112,7 @@ exports[`internet > 42 > url > without slash appended and with http protocol 1`] exports[`internet > 42 > userAgent 1`] = `"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:131.0) Gecko/20100101 Firefox/118.0"`; -exports[`internet > 42 > userName > noArgs 1`] = `"Garnet.Reynolds-Miller15"`; +exports[`internet > 42 > userName > noArgs 1`] = `"Moses.Crist"`; exports[`internet > 42 > userName > with Chinese names 1`] = `"hlzp8d.tpv"`; @@ -124,11 +124,11 @@ exports[`internet > 42 > userName > with accented names 1`] = `"Helene.Muller"`; exports[`internet > 42 > userName > with all option 1`] = `"Jane.Doe"`; -exports[`internet > 42 > userName > with firstName option 1`] = `"Jane_Wiegand59"`; +exports[`internet > 42 > userName > with firstName option 1`] = `"Jane.Reynolds-Miller15"`; -exports[`internet > 42 > userName > with lastName option 1`] = `"Garnet_Doe"`; +exports[`internet > 42 > userName > with lastName option 1`] = `"Moses_Doe15"`; -exports[`internet > 42 > username > noArgs 1`] = `"Garnet.Reynolds-Miller15"`; +exports[`internet > 42 > username > noArgs 1`] = `"Moses.Crist"`; exports[`internet > 42 > username > with Chinese names 1`] = `"hlzp8d.tpv"`; @@ -140,9 +140,9 @@ exports[`internet > 42 > username > with accented names 1`] = `"Helene.Muller"`; exports[`internet > 42 > username > with all option 1`] = `"Jane.Doe"`; -exports[`internet > 42 > username > with firstName option 1`] = `"Jane_Wiegand59"`; +exports[`internet > 42 > username > with firstName option 1`] = `"Jane.Reynolds-Miller15"`; -exports[`internet > 42 > username > with lastName option 1`] = `"Garnet_Doe"`; +exports[`internet > 42 > username > with lastName option 1`] = `"Moses_Doe15"`; exports[`internet > 1211 > color > noArgs 1`] = `"#77721c"`; @@ -154,7 +154,7 @@ exports[`internet > 1211 > color > with greenBase option 1`] = `"#77a41c"`; exports[`internet > 1211 > color > with redBase option 1`] = `"#a9721c"`; -exports[`internet > 1211 > displayName > noArgs 1`] = `"Tito_Fahey67"`; +exports[`internet > 1211 > displayName > noArgs 1`] = `"Dane_Paucek35"`; exports[`internet > 1211 > displayName > with Chinese names 1`] = `"大羽89"`; @@ -166,9 +166,9 @@ exports[`internet > 1211 > displayName > with accented names 1`] = `"Hélene89"` exports[`internet > 1211 > displayName > with all option 1`] = `"Jane89"`; -exports[`internet > 1211 > displayName > with firstName option 1`] = `"Jane.Trantow99"`; +exports[`internet > 1211 > displayName > with firstName option 1`] = `"Jane_Fahey67"`; -exports[`internet > 1211 > displayName > with lastName option 1`] = `"Tito_Doe22"`; +exports[`internet > 1211 > displayName > with lastName option 1`] = `"Dane_Doe67"`; exports[`internet > 1211 > domainName 1`] = `"velvety-tarragon.biz"`; @@ -176,31 +176,31 @@ exports[`internet > 1211 > domainSuffix 1`] = `"org"`; exports[`internet > 1211 > domainWord 1`] = `"velvety-tarragon"`; -exports[`internet > 1211 > email > noArgs 1`] = `"Skye68@hotmail.com"`; +exports[`internet > 1211 > email > noArgs 1`] = `"Woodrow69@hotmail.com"`; exports[`internet > 1211 > email > with all options 1`] = `"Jane_Doe89@fakerjs.dev"`; -exports[`internet > 1211 > email > with allowSpecialCharacters option 1`] = `"Skye68@hotmail.com"`; +exports[`internet > 1211 > email > with allowSpecialCharacters option 1`] = `"Woodrow69@hotmail.com"`; -exports[`internet > 1211 > email > with firstName option 1`] = `"Jane67@hotmail.com"`; +exports[`internet > 1211 > email > with firstName option 1`] = `"Jane68@hotmail.com"`; -exports[`internet > 1211 > email > with lastName option 1`] = `"Skye.Doe@hotmail.com"`; +exports[`internet > 1211 > email > with lastName option 1`] = `"Woodrow_Doe@hotmail.com"`; -exports[`internet > 1211 > email > with provider option 1`] = `"Tito67@fakerjs.dev"`; +exports[`internet > 1211 > email > with provider option 1`] = `"Dane35@fakerjs.dev"`; exports[`internet > 1211 > emoji > noArgs 1`] = `"🇹🇳"`; exports[`internet > 1211 > emoji > with options 1`] = `"🌲"`; -exports[`internet > 1211 > exampleEmail > noArgs 1`] = `"Skye68@example.net"`; +exports[`internet > 1211 > exampleEmail > noArgs 1`] = `"Woodrow69@example.net"`; exports[`internet > 1211 > exampleEmail > with all options 1`] = `"Jane_Doe@example.net"`; -exports[`internet > 1211 > exampleEmail > with allowSpecialCharacters option 1`] = `"Skye68@example.net"`; +exports[`internet > 1211 > exampleEmail > with allowSpecialCharacters option 1`] = `"Woodrow69@example.net"`; -exports[`internet > 1211 > exampleEmail > with firstName option 1`] = `"Jane67@example.net"`; +exports[`internet > 1211 > exampleEmail > with firstName option 1`] = `"Jane68@example.net"`; -exports[`internet > 1211 > exampleEmail > with lastName option 1`] = `"Skye.Doe@example.net"`; +exports[`internet > 1211 > exampleEmail > with lastName option 1`] = `"Woodrow_Doe@example.net"`; exports[`internet > 1211 > httpMethod 1`] = `"PATCH"`; @@ -256,7 +256,7 @@ exports[`internet > 1211 > url > without slash appended and with http protocol 1 exports[`internet > 1211 > userAgent 1`] = `"Mozilla/5.0 (Linux; Android 13; SM-G998B) AppleWebKit/605.67 (KHTML, like Gecko) Chrome/107.7.7.14 Mobile Safari/592.76"`; -exports[`internet > 1211 > userName > noArgs 1`] = `"Tito67"`; +exports[`internet > 1211 > userName > noArgs 1`] = `"Dane35"`; exports[`internet > 1211 > userName > with Chinese names 1`] = `"hlzp8d_tpv89"`; @@ -268,11 +268,11 @@ exports[`internet > 1211 > userName > with accented names 1`] = `"Helene_Muller8 exports[`internet > 1211 > userName > with all option 1`] = `"Jane_Doe89"`; -exports[`internet > 1211 > userName > with firstName option 1`] = `"Jane99"`; +exports[`internet > 1211 > userName > with firstName option 1`] = `"Jane67"`; -exports[`internet > 1211 > userName > with lastName option 1`] = `"Tito_Doe"`; +exports[`internet > 1211 > userName > with lastName option 1`] = `"Dane_Doe"`; -exports[`internet > 1211 > username > noArgs 1`] = `"Tito67"`; +exports[`internet > 1211 > username > noArgs 1`] = `"Dane35"`; exports[`internet > 1211 > username > with Chinese names 1`] = `"hlzp8d_tpv89"`; @@ -284,9 +284,9 @@ exports[`internet > 1211 > username > with accented names 1`] = `"Helene_Muller8 exports[`internet > 1211 > username > with all option 1`] = `"Jane_Doe89"`; -exports[`internet > 1211 > username > with firstName option 1`] = `"Jane99"`; +exports[`internet > 1211 > username > with firstName option 1`] = `"Jane67"`; -exports[`internet > 1211 > username > with lastName option 1`] = `"Tito_Doe"`; +exports[`internet > 1211 > username > with lastName option 1`] = `"Dane_Doe"`; exports[`internet > 1337 > color > noArgs 1`] = `"#211423"`; @@ -298,7 +298,7 @@ exports[`internet > 1337 > color > with greenBase option 1`] = `"#214623"`; exports[`internet > 1337 > color > with redBase option 1`] = `"#531423"`; -exports[`internet > 1337 > displayName > noArgs 1`] = `"Devyn.Gottlieb"`; +exports[`internet > 1337 > displayName > noArgs 1`] = `"Emma.Leannon97"`; exports[`internet > 1337 > displayName > with Chinese names 1`] = `"大羽15"`; @@ -310,9 +310,9 @@ exports[`internet > 1337 > displayName > with accented names 1`] = `"Hélene15"` exports[`internet > 1337 > displayName > with all option 1`] = `"Jane15"`; -exports[`internet > 1337 > displayName > with firstName option 1`] = `"Jane45"`; +exports[`internet > 1337 > displayName > with firstName option 1`] = `"Jane.Gottlieb"`; -exports[`internet > 1337 > displayName > with lastName option 1`] = `"Devyn.Doe"`; +exports[`internet > 1337 > displayName > with lastName option 1`] = `"Emma.Doe"`; exports[`internet > 1337 > domainName 1`] = `"fatal-co-producer.biz"`; @@ -320,31 +320,31 @@ exports[`internet > 1337 > domainSuffix 1`] = `"biz"`; exports[`internet > 1337 > domainWord 1`] = `"fatal-co-producer"`; -exports[`internet > 1337 > email > noArgs 1`] = `"Carmella.Koelpin51@gmail.com"`; +exports[`internet > 1337 > email > noArgs 1`] = `"Johnnie_Gibson73@gmail.com"`; exports[`internet > 1337 > email > with all options 1`] = `"Jane.Doe15@fakerjs.dev"`; -exports[`internet > 1337 > email > with allowSpecialCharacters option 1`] = `"Carmella.Koelpin51@gmail.com"`; +exports[`internet > 1337 > email > with allowSpecialCharacters option 1`] = `"Johnnie?Gibson73@gmail.com"`; -exports[`internet > 1337 > email > with firstName option 1`] = `"Jane.Gottlieb@gmail.com"`; +exports[`internet > 1337 > email > with firstName option 1`] = `"Jane.Koelpin51@gmail.com"`; -exports[`internet > 1337 > email > with lastName option 1`] = `"Carmella.Doe45@gmail.com"`; +exports[`internet > 1337 > email > with lastName option 1`] = `"Johnnie.Doe51@gmail.com"`; -exports[`internet > 1337 > email > with provider option 1`] = `"Devyn.Gottlieb@fakerjs.dev"`; +exports[`internet > 1337 > email > with provider option 1`] = `"Emma97@fakerjs.dev"`; exports[`internet > 1337 > emoji > noArgs 1`] = `"🧏🏾‍♂️"`; exports[`internet > 1337 > emoji > with options 1`] = `"🐪"`; -exports[`internet > 1337 > exampleEmail > noArgs 1`] = `"Carmella.Koelpin51@example.org"`; +exports[`internet > 1337 > exampleEmail > noArgs 1`] = `"Johnnie_Gibson73@example.org"`; exports[`internet > 1337 > exampleEmail > with all options 1`] = `"Jane/Doe27@example.org"`; -exports[`internet > 1337 > exampleEmail > with allowSpecialCharacters option 1`] = `"Carmella.Koelpin51@example.org"`; +exports[`internet > 1337 > exampleEmail > with allowSpecialCharacters option 1`] = `"Johnnie?Gibson73@example.org"`; -exports[`internet > 1337 > exampleEmail > with firstName option 1`] = `"Jane.Gottlieb@example.org"`; +exports[`internet > 1337 > exampleEmail > with firstName option 1`] = `"Jane.Koelpin51@example.org"`; -exports[`internet > 1337 > exampleEmail > with lastName option 1`] = `"Carmella.Doe45@example.org"`; +exports[`internet > 1337 > exampleEmail > with lastName option 1`] = `"Johnnie.Doe51@example.org"`; exports[`internet > 1337 > httpMethod 1`] = `"POST"`; @@ -400,7 +400,7 @@ exports[`internet > 1337 > url > without slash appended and with http protocol 1 exports[`internet > 1337 > userAgent 1`] = `"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/547.27.45 (KHTML, like Gecko) Version/16.1 Safari/558.51.26"`; -exports[`internet > 1337 > userName > noArgs 1`] = `"Devyn.Gottlieb"`; +exports[`internet > 1337 > userName > noArgs 1`] = `"Emma97"`; exports[`internet > 1337 > userName > with Chinese names 1`] = `"hlzp8d.tpv15"`; @@ -412,11 +412,11 @@ exports[`internet > 1337 > userName > with accented names 1`] = `"Helene.Muller1 exports[`internet > 1337 > userName > with all option 1`] = `"Jane.Doe15"`; -exports[`internet > 1337 > userName > with firstName option 1`] = `"Jane.Cronin45"`; +exports[`internet > 1337 > userName > with firstName option 1`] = `"Jane.Gottlieb"`; -exports[`internet > 1337 > userName > with lastName option 1`] = `"Devyn.Doe27"`; +exports[`internet > 1337 > userName > with lastName option 1`] = `"Emma.Doe"`; -exports[`internet > 1337 > username > noArgs 1`] = `"Devyn.Gottlieb"`; +exports[`internet > 1337 > username > noArgs 1`] = `"Emma97"`; exports[`internet > 1337 > username > with Chinese names 1`] = `"hlzp8d.tpv15"`; @@ -428,6 +428,6 @@ exports[`internet > 1337 > username > with accented names 1`] = `"Helene.Muller1 exports[`internet > 1337 > username > with all option 1`] = `"Jane.Doe15"`; -exports[`internet > 1337 > username > with firstName option 1`] = `"Jane.Cronin45"`; +exports[`internet > 1337 > username > with firstName option 1`] = `"Jane.Gottlieb"`; -exports[`internet > 1337 > username > with lastName option 1`] = `"Devyn.Doe27"`; +exports[`internet > 1337 > username > with lastName option 1`] = `"Emma.Doe"`; diff --git a/test/modules/__snapshots__/person.spec.ts.snap b/test/modules/__snapshots__/person.spec.ts.snap index 45d89c22d69..3d9f47007c7 100644 --- a/test/modules/__snapshots__/person.spec.ts.snap +++ b/test/modules/__snapshots__/person.spec.ts.snap @@ -2,19 +2,19 @@ exports[`person > 42 > bio 1`] = `"traveler, philosopher, model"`; -exports[`person > 42 > firstName > noArgs 1`] = `"Garnet"`; +exports[`person > 42 > firstName > noArgs 1`] = `"Moses"`; -exports[`person > 42 > firstName > with sex 1`] = `"Gerald"`; +exports[`person > 42 > firstName > with sex 1`] = `"Tyrone"`; -exports[`person > 42 > fullName > noArgs 1`] = `"Tracy Miller"`; +exports[`person > 42 > fullName > noArgs 1`] = `"Moses Crist"`; exports[`person > 42 > fullName > with all (sex) 1`] = `"John Doe"`; exports[`person > 42 > fullName > with firstName 1`] = `"John Reynolds-Miller"`; -exports[`person > 42 > fullName > with lastName 1`] = `"Tracy Doe"`; +exports[`person > 42 > fullName > with lastName 1`] = `"Moses Doe"`; -exports[`person > 42 > fullName > with sex 1`] = `"Hilda Reynolds-Miller"`; +exports[`person > 42 > fullName > with sex 1`] = `"Tracy Miller"`; exports[`person > 42 > gender 1`] = `"Gender nonconforming"`; @@ -26,23 +26,27 @@ exports[`person > 42 > jobTitle 1`] = `"National Usability Producer"`; exports[`person > 42 > jobType 1`] = `"Coordinator"`; -exports[`person > 42 > lastName > noArgs 1`] = `"Wiegand"`; +exports[`person > 42 > lastName > noArgs 1`] = `"Reynolds-Miller"`; exports[`person > 42 > lastName > with sex 1`] = `"Wiegand"`; -exports[`person > 42 > middleName > noArgs 1`] = `"Greer"`; +exports[`person > 42 > middleName > noArgs 1`] = `"Quinn"`; -exports[`person > 42 > middleName > with sex 1`] = `"Houston"`; +exports[`person > 42 > middleName > with sex 1`] = `"William"`; -exports[`person > 42 > prefix > noArgs 1`] = `"Miss"`; +exports[`person > 42 > prefix > noArgs 1`] = `"Mrs."`; -exports[`person > 42 > prefix > with sex 1`] = `"Dr."`; +exports[`person > 42 > prefix > with sex 1`] = `"Mr."`; exports[`person > 42 > sex > noArgs 1`] = `"female"`; exports[`person > 42 > sex > with sex 1`] = `"female"`; -exports[`person > 42 > sexType 1`] = `"female"`; +exports[`person > 42 > sexType > noArgs 1`] = `"female"`; + +exports[`person > 42 > sexType > with includeGeneric=false 1`] = `"female"`; + +exports[`person > 42 > sexType > with includeGeneric=true 1`] = `"generic"`; exports[`person > 42 > suffix > noArgs 1`] = `"III"`; @@ -52,19 +56,19 @@ exports[`person > 42 > zodiacSign 1`] = `"Gemini"`; exports[`person > 1211 > bio 1`] = `"decongestant supporter, parent 🎲"`; -exports[`person > 1211 > firstName > noArgs 1`] = `"Tito"`; +exports[`person > 1211 > firstName > noArgs 1`] = `"Dane"`; -exports[`person > 1211 > firstName > with sex 1`] = `"Todd"`; +exports[`person > 1211 > firstName > with sex 1`] = `"Skye"`; -exports[`person > 1211 > fullName > noArgs 1`] = `"Steve Zieme"`; +exports[`person > 1211 > fullName > noArgs 1`] = `"Dane Osinski-Paucek"`; exports[`person > 1211 > fullName > with all (sex) 1`] = `"John Doe PhD"`; -exports[`person > 1211 > fullName > with firstName 1`] = `"Mr. John Fahey MD"`; +exports[`person > 1211 > fullName > with firstName 1`] = `"Mrs. John Fahey DDS"`; -exports[`person > 1211 > fullName > with lastName 1`] = `"Steve Doe"`; +exports[`person > 1211 > fullName > with lastName 1`] = `"Mrs. Dane Doe DDS"`; -exports[`person > 1211 > fullName > with sex 1`] = `"Mrs. Teri Fahey MD"`; +exports[`person > 1211 > fullName > with sex 1`] = `"Skye Zieme"`; exports[`person > 1211 > gender 1`] = `"Trigender"`; @@ -76,23 +80,27 @@ exports[`person > 1211 > jobTitle 1`] = `"Chief Interactions Manager"`; exports[`person > 1211 > jobType 1`] = `"Representative"`; -exports[`person > 1211 > lastName > noArgs 1`] = `"Trantow"`; +exports[`person > 1211 > lastName > noArgs 1`] = `"Fahey"`; exports[`person > 1211 > lastName > with sex 1`] = `"Trantow"`; -exports[`person > 1211 > middleName > noArgs 1`] = `"Sawyer"`; +exports[`person > 1211 > middleName > noArgs 1`] = `"Cameron"`; -exports[`person > 1211 > middleName > with sex 1`] = `"Walter"`; +exports[`person > 1211 > middleName > with sex 1`] = `"Sage"`; -exports[`person > 1211 > prefix > noArgs 1`] = `"Ms."`; +exports[`person > 1211 > prefix > noArgs 1`] = `"Miss"`; -exports[`person > 1211 > prefix > with sex 1`] = `"Mr."`; +exports[`person > 1211 > prefix > with sex 1`] = `"Ms."`; exports[`person > 1211 > sex > noArgs 1`] = `"male"`; exports[`person > 1211 > sex > with sex 1`] = `"male"`; -exports[`person > 1211 > sexType 1`] = `"male"`; +exports[`person > 1211 > sexType > noArgs 1`] = `"male"`; + +exports[`person > 1211 > sexType > with includeGeneric=false 1`] = `"male"`; + +exports[`person > 1211 > sexType > with includeGeneric=true 1`] = `"male"`; exports[`person > 1211 > suffix > noArgs 1`] = `"DVM"`; @@ -102,19 +110,19 @@ exports[`person > 1211 > zodiacSign 1`] = `"Capricorn"`; exports[`person > 1337 > bio 1`] = `"creator, engineer, friend"`; -exports[`person > 1337 > firstName > noArgs 1`] = `"Devyn"`; +exports[`person > 1337 > firstName > noArgs 1`] = `"Emma"`; -exports[`person > 1337 > firstName > with sex 1`] = `"Douglas"`; +exports[`person > 1337 > firstName > with sex 1`] = `"Christopher"`; -exports[`person > 1337 > fullName > noArgs 1`] = `"Chelsea Koelpin"`; +exports[`person > 1337 > fullName > noArgs 1`] = `"Emma Hammes"`; exports[`person > 1337 > fullName > with all (sex) 1`] = `"John Doe"`; exports[`person > 1337 > fullName > with firstName 1`] = `"John Gottlieb"`; -exports[`person > 1337 > fullName > with lastName 1`] = `"Chelsea Doe"`; +exports[`person > 1337 > fullName > with lastName 1`] = `"Emma Doe"`; -exports[`person > 1337 > fullName > with sex 1`] = `"Elizabeth Gottlieb"`; +exports[`person > 1337 > fullName > with sex 1`] = `"Chelsea Koelpin"`; exports[`person > 1337 > gender 1`] = `"Demigender"`; @@ -126,13 +134,13 @@ exports[`person > 1337 > jobTitle 1`] = `"Future Marketing Engineer"`; exports[`person > 1337 > jobType 1`] = `"Engineer"`; -exports[`person > 1337 > lastName > noArgs 1`] = `"Cronin"`; +exports[`person > 1337 > lastName > noArgs 1`] = `"Gottlieb"`; exports[`person > 1337 > lastName > with sex 1`] = `"Cronin"`; -exports[`person > 1337 > middleName > noArgs 1`] = `"Dakota"`; +exports[`person > 1337 > middleName > noArgs 1`] = `"Dylan"`; -exports[`person > 1337 > middleName > with sex 1`] = `"Ethan"`; +exports[`person > 1337 > middleName > with sex 1`] = `"Christopher"`; exports[`person > 1337 > prefix > noArgs 1`] = `"Miss"`; @@ -142,7 +150,11 @@ exports[`person > 1337 > sex > noArgs 1`] = `"female"`; exports[`person > 1337 > sex > with sex 1`] = `"female"`; -exports[`person > 1337 > sexType 1`] = `"female"`; +exports[`person > 1337 > sexType > noArgs 1`] = `"female"`; + +exports[`person > 1337 > sexType > with includeGeneric=false 1`] = `"female"`; + +exports[`person > 1337 > sexType > with includeGeneric=true 1`] = `"female"`; exports[`person > 1337 > suffix > noArgs 1`] = `"I"`; diff --git a/test/modules/person.spec.ts b/test/modules/person.spec.ts index 922da6e50ce..36b09dc66c6 100644 --- a/test/modules/person.spec.ts +++ b/test/modules/person.spec.ts @@ -8,7 +8,6 @@ const NON_SEEDED_BASED_RUN = 5; describe('person', () => { seededTests(faker, 'person', (t) => { t.itEach( - 'sexType', 'gender', 'jobTitle', 'jobDescriptor', @@ -17,6 +16,13 @@ describe('person', () => { 'bio' ); + t.describe('sexType', (t) => + t + .it('noArgs') + .it('with includeGeneric=true', { includeGeneric: true }) + .it('with includeGeneric=false', { includeGeneric: false }) + ); + t.describeEach( 'firstName', 'lastName', @@ -53,11 +59,22 @@ describe('person', () => { }); it('should return a sex-specific first name', () => { - let name = faker.person.firstName('female'); - expect(faker.definitions.person.first_name.female).toContain(name); + let name = faker.person.firstName('generic'); + expect(faker.definitions.person.first_name.generic).toContain(name); + + name = faker.person.firstName('female'); + const female_applicable = [ + ...(faker.definitions.person.first_name.generic ?? []), + ...(faker.definitions.person.first_name.female ?? []), + ]; + expect(female_applicable).toContain(name); name = faker.person.firstName('male'); - expect(faker.definitions.person.first_name.male).toContain(name); + const male_applicable = [ + ...(faker.definitions.person.first_name.generic ?? []), + ...(faker.definitions.person.first_name.male ?? []), + ]; + expect(male_applicable).toContain(name); }); it('should return a sex-specific first name when no sex-specific first name was defined', () => { @@ -96,13 +113,29 @@ describe('person', () => { it('should return a middle name when passed en locale', () => { let name = faker.person.middleName(); + const allApplicable = [ + ...(faker.definitions.person.middle_name.generic ?? []), + ...(faker.definitions.person.middle_name.female ?? []), + ...(faker.definitions.person.middle_name.male ?? []), + ]; + expect(allApplicable).toContain(name); + + name = faker.person.middleName('generic'); expect(faker.definitions.person.middle_name.generic).toContain(name); name = faker.person.middleName('female'); - expect(faker.definitions.person.middle_name.female).toContain(name); + const female_applicable = [ + ...(faker.definitions.person.middle_name.generic ?? []), + ...(faker.definitions.person.middle_name.female ?? []), + ]; + expect(female_applicable).toContain(name); name = faker.person.middleName('male'); - expect(faker.definitions.person.middle_name.male).toContain(name); + const male_applicable = [ + ...(faker.definitions.person.middle_name.generic ?? []), + ...(faker.definitions.person.middle_name.male ?? []), + ]; + expect(male_applicable).toContain(name); }); it('should return a sex-specific middle name', () => { @@ -122,11 +155,14 @@ describe('person', () => { expect(fullName).toContain(' '); }); - it('should return a female sex-specific name without firstName and lastName', () => { - const female_specific = [ + it('should return a female applicable name without firstName and lastName', () => { + const female_applicable = [ ...(fakerMK.rawDefinitions.person?.prefix?.female ?? []), ...(fakerMK.rawDefinitions.person?.first_name?.female ?? []), ...(fakerMK.rawDefinitions.person?.last_name?.female ?? []), + ...(fakerMK.rawDefinitions.person?.prefix?.generic ?? []), + ...(fakerMK.rawDefinitions.person?.first_name?.generic ?? []), + ...(fakerMK.rawDefinitions.person?.last_name?.generic ?? []), // ...(fakerMK.rawDefinitions.person?.suffix ?? []), Not applicable ]; @@ -134,15 +170,18 @@ describe('person', () => { const parts = fullName.split(' '); for (const part of parts) { - expect(female_specific).toContain(part); + expect(female_applicable).toContain(part); } }); - it('should return a male sex-specific name without firstName and lastName', () => { - const male_specific = [ + it('should return a male applicable name without firstName and lastName', () => { + const male_applicable = [ ...(fakerMK.rawDefinitions.person?.prefix?.male ?? []), ...(fakerMK.rawDefinitions.person?.first_name?.male ?? []), ...(fakerMK.rawDefinitions.person?.last_name?.male ?? []), + ...(fakerMK.rawDefinitions.person?.prefix?.generic ?? []), + ...(fakerMK.rawDefinitions.person?.first_name?.generic ?? []), + ...(fakerMK.rawDefinitions.person?.last_name?.generic ?? []), // ...(fakerMK.rawDefinitions.person?.suffix ?? []), Not applicable ]; @@ -150,13 +189,14 @@ describe('person', () => { const parts = fullName.split(' '); for (const part of parts) { - expect(male_specific).toContain(part); + expect(male_applicable).toContain(part); } }); - it('should return a female sex-specific name with given firstName and lastName', () => { - const male_specific = [ + it('should return a female applicable name with given firstName and lastName', () => { + const female_applicable = [ ...(fakerMK.rawDefinitions.person?.prefix?.female ?? []), + ...(fakerMK.rawDefinitions.person?.prefix?.generic ?? []), 'firstName', 'lastName', // ...(fakerMK.rawDefinitions.person?.suffix ?? []), Not applicable @@ -170,13 +210,14 @@ describe('person', () => { const parts = fullName.split(' '); for (const part of parts) { - expect(male_specific).toContain(part); + expect(female_applicable).toContain(part); } }); - it('should return a male sex-specific name with given firstName and lastName', () => { - const male_specific = [ + it('should return a male applicable name with given firstName and lastName', () => { + const male_applicable = [ ...(fakerMK.rawDefinitions.person?.prefix?.male ?? []), + ...(fakerMK.rawDefinitions.person?.prefix?.generic ?? []), 'firstName', 'lastName', // ...(fakerMK.rawDefinitions.person?.suffix ?? []), Not applicable @@ -190,7 +231,7 @@ describe('person', () => { const parts = fullName.split(' '); for (const part of parts) { - expect(male_specific).toContain(part); + expect(male_applicable).toContain(part); } }); }); @@ -214,9 +255,23 @@ describe('person', () => { }); describe('sexType()', () => { - it('should return a sex type', () => { + it('should return a sex type without generic by default', () => { const sexType = faker.person.sexType(); + expect(sexType).toBeTypeOf('string'); + expect([Sex.Female, Sex.Male]).toContain(sexType); + }); + + it('should return a sex type explicitly without generic', () => { + const sexType = faker.person.sexType({ includeGeneric: false }); + + expect(sexType).toBeTypeOf('string'); + expect([Sex.Female, Sex.Male]).toContain(sexType); + }); + + it('should return a sex type including generic', () => { + const sexType = faker.person.sexType({ includeGeneric: true }); + expect(sexType).toBeTypeOf('string'); expect(Object.values(Sex)).toContain(sexType); }); @@ -227,21 +282,41 @@ describe('person', () => { const prefix = faker.person.prefix(); expect(prefix).toBeTypeOf('string'); - expect(faker.definitions.person.prefix.generic).toContain(prefix); + const all_applicable = [ + ...(faker.definitions.person.prefix.generic ?? []), + ...(faker.definitions.person.prefix.female ?? []), + ...(faker.definitions.person.prefix.male ?? []), + ]; + expect(all_applicable).toContain(prefix); + }); + + it('should return a generic prefix with given string', () => { + const prefix = fakerMK.person.prefix('generic'); + + expect(prefix).toBeTypeOf('string'); + expect(fakerMK.definitions.person.prefix.generic).toContain(prefix); }); it('should return a female prefix with given string', () => { const prefix = fakerMK.person.prefix('female'); expect(prefix).toBeTypeOf('string'); - expect(fakerMK.definitions.person.prefix.female).toContain(prefix); + const female_applicable = [ + ...(fakerMK.definitions.person.prefix.generic ?? []), + ...(fakerMK.definitions.person.prefix.female ?? []), + ]; + expect(female_applicable).toContain(prefix); }); it('should return a male prefix with given string', () => { const prefix = fakerMK.person.prefix('male'); expect(prefix).toBeTypeOf('string'); - expect(fakerMK.definitions.person.prefix.male).toContain(prefix); + const male_applicable = [ + ...(fakerMK.definitions.person.prefix.generic ?? []), + ...(fakerMK.definitions.person.prefix.male ?? []), + ]; + expect(male_applicable).toContain(prefix); }); });