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

feat(name): add sexType method #1289

Merged
merged 4 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/modules/name/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@ export class Name {
return this.faker.helpers.arrayElement(this.faker.definitions.name.sex);
}

/**
* Returns a random sex type.
*
* @example
* faker.name.sexType() // Sex.Female
*/
sexType(): SexType {
return this.faker.helpers.objectValue(Sex);
}

/**
* Returns a random name prefix.
*
Expand Down
6 changes: 6 additions & 0 deletions test/__snapshots__/name.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ exports[`name > 42 > sex > noArgs 1`] = `"female"`;

exports[`name > 42 > sex > with gender 1`] = `"female"`;

exports[`name > 42 > sexType 1`] = `"female"`;

exports[`name > 42 > suffix > noArgs 1`] = `"III"`;

exports[`name > 42 > suffix > with gender 1`] = `"III"`;
Expand Down Expand Up @@ -112,6 +114,8 @@ exports[`name > 1211 > sex > noArgs 1`] = `"male"`;

exports[`name > 1211 > sex > with gender 1`] = `"male"`;

exports[`name > 1211 > sexType 1`] = `"male"`;

exports[`name > 1211 > suffix > noArgs 1`] = `"DVM"`;

exports[`name > 1211 > suffix > with gender 1`] = `"DVM"`;
Expand Down Expand Up @@ -170,6 +174,8 @@ exports[`name > 1337 > sex > noArgs 1`] = `"female"`;

exports[`name > 1337 > sex > with gender 1`] = `"female"`;

exports[`name > 1337 > sexType 1`] = `"female"`;

exports[`name > 1337 > suffix > noArgs 1`] = `"I"`;

exports[`name > 1337 > suffix > with gender 1`] = `"I"`;
13 changes: 11 additions & 2 deletions test/name.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { faker } from '../src';
import { faker, Sex } from '../src';
import { seededTests } from './support/seededRuns';

const NON_SEEDED_BASED_RUN = 5;
Expand All @@ -11,7 +11,7 @@ describe('name', () => {
});

seededTests(faker, 'name', (t) => {
t.itEach('jobTitle', 'jobDescriptor', 'jobArea', 'jobType');
t.itEach('sexType', 'jobTitle', 'jobDescriptor', 'jobArea', 'jobType');

t.describeEach(
'firstName',
Expand Down Expand Up @@ -365,6 +365,15 @@ describe('name', () => {
});
});

describe('sexType()', () => {
it('should return a sex type', () => {
const sexType = faker.name.sexType();

expect(sexType).toBeTypeOf('string');
expect(Object.values(Sex)).toContain(sexType);
});
});

describe('prefix()', () => {
beforeEach(() => {
faker.locale = 'en';
Expand Down