aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLeyla Jähnig <[email protected]>2022-07-19 10:07:28 +0200
committerGitHub <[email protected]>2022-07-19 08:07:28 +0000
commit316f61fdc4c9feaeebb9696982da92ae05608919 (patch)
treeca42af741c25c12914f6202df57f0e633c8c1280 /test
parentea91fe65ce2ad923c73edfbf35ced82643aeb924 (diff)
downloadfaker-316f61fdc4c9feaeebb9696982da92ae05608919.tar.xz
faker-316f61fdc4c9feaeebb9696982da92ae05608919.zip
refactor(name.findName): rename to fullName (#1127)
Diffstat (limited to 'test')
-rw-r--r--test/__snapshots__/name.spec.ts.snap6
-rw-r--r--test/name.spec.ts110
2 files changed, 109 insertions, 7 deletions
diff --git a/test/__snapshots__/name.spec.ts.snap b/test/__snapshots__/name.spec.ts.snap
index e07b6047..32cd8cdc 100644
--- a/test/__snapshots__/name.spec.ts.snap
+++ b/test/__snapshots__/name.spec.ts.snap
@@ -4,6 +4,8 @@ exports[`name > seed: 42 > findName() 1`] = `"Sadie Wiegand"`;
exports[`name > seed: 42 > firstName() 1`] = `"Garnett"`;
+exports[`name > seed: 42 > fullName() 1`] = `"Sadie Wiegand"`;
+
exports[`name > seed: 42 > gender() 1`] = `"Gender nonconforming"`;
exports[`name > seed: 42 > jobArea() 1`] = `"Identity"`;
@@ -26,6 +28,8 @@ exports[`name > seed: 1211 > findName() 1`] = `"Claude Trantow"`;
exports[`name > seed: 1211 > firstName() 1`] = `"Tito"`;
+exports[`name > seed: 1211 > fullName() 1`] = `"Claude Trantow"`;
+
exports[`name > seed: 1211 > gender() 1`] = `"Trigender"`;
exports[`name > seed: 1211 > jobArea() 1`] = `"Factors"`;
@@ -48,6 +52,8 @@ exports[`name > seed: 1337 > findName() 1`] = `"Leona Cronin"`;
exports[`name > seed: 1337 > firstName() 1`] = `"Devyn"`;
+exports[`name > seed: 1337 > fullName() 1`] = `"Leona Cronin"`;
+
exports[`name > seed: 1337 > gender() 1`] = `"Demigender"`;
exports[`name > seed: 1337 > jobArea() 1`] = `"Functionality"`;
diff --git a/test/name.spec.ts b/test/name.spec.ts
index 1d9f4421..c7baf5a9 100644
--- a/test/name.spec.ts
+++ b/test/name.spec.ts
@@ -1,21 +1,23 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { faker } from '../src';
+import type { Name } from '../src/modules/name';
import { seededRuns } from './support/seededRuns';
const NON_SEEDED_BASED_RUN = 5;
-const functionNames = [
+const functionNames: (keyof Name)[] = [
+ 'findName',
'firstName',
+ 'fullName',
+ 'gender',
+ 'jobArea',
+ 'jobDescriptor',
+ 'jobTitle',
+ 'jobType',
'lastName',
'middleName',
- 'findName',
- 'jobTitle',
- 'gender',
'prefix',
'suffix',
- 'jobDescriptor',
- 'jobArea',
- 'jobType',
];
describe('name', () => {
@@ -226,6 +228,100 @@ describe('name', () => {
});
});
+ describe('fullName()', () => {
+ beforeEach(() => {
+ faker.locale = 'en';
+ faker.localeFallback = 'en';
+ });
+
+ it('should return a name with firstName and lastName', () => {
+ const fullName = faker.name.fullName();
+
+ expect(fullName).toBeTypeOf('string');
+ expect(fullName).toContain(' ');
+ });
+
+ it('should return a female gender-specific name without firstName and lastName', () => {
+ faker.locale = 'mk';
+
+ const female_specific = [
+ ...faker.definitions.name.female_prefix,
+ ...faker.definitions.name.female_first_name,
+ ...faker.definitions.name.female_last_name,
+ ...faker.definitions.name.suffix,
+ ];
+
+ const fullName = faker.name.fullName({ gender: 'female' });
+
+ const parts = fullName.split(' ');
+ for (const part of parts) {
+ expect(female_specific).toContain(part);
+ }
+ });
+
+ it('should return a male gender-specific name without firstName and lastName', () => {
+ faker.locale = 'mk';
+
+ const male_specific = [
+ ...faker.definitions.name.male_prefix,
+ ...faker.definitions.name.male_first_name,
+ ...faker.definitions.name.male_last_name,
+ ...faker.definitions.name.suffix,
+ ];
+
+ const fullName = faker.name.fullName({ gender: 'male' });
+
+ const parts = fullName.split(' ');
+ for (const part of parts) {
+ expect(male_specific).toContain(part);
+ }
+ });
+
+ it('should return a female gender-specific name with given firstName and lastName', () => {
+ faker.locale = 'mk';
+
+ const male_specific = [
+ ...faker.definitions.name.female_prefix,
+ 'firstName',
+ 'lastName',
+ ...faker.definitions.name.suffix,
+ ];
+
+ const fullName = faker.name.fullName({
+ firstName: 'firstName',
+ lastName: 'lastName',
+ gender: 'female',
+ });
+
+ const parts = fullName.split(' ');
+ for (const part of parts) {
+ expect(male_specific).toContain(part);
+ }
+ });
+
+ it('should return a male gender-specific name with given firstName and lastName', () => {
+ faker.locale = 'mk';
+
+ const male_specific = [
+ ...faker.definitions.name.male_prefix,
+ 'firstName',
+ 'lastName',
+ ...faker.definitions.name.suffix,
+ ];
+
+ const fullName = faker.name.fullName({
+ firstName: 'firstName',
+ lastName: 'lastName',
+ gender: 'male',
+ });
+
+ const parts = fullName.split(' ');
+ for (const part of parts) {
+ expect(male_specific).toContain(part);
+ }
+ });
+ });
+
describe('gender()', () => {
beforeEach(() => {
faker.locale = 'en';