Skip to content

Commit

Permalink
feat(name): add sexType method
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Aug 19, 2022
1 parent cc8b2b2 commit 4952b22
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
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.arrayElement(Object.values(Sex));
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

exports[`name > 1337 > suffix > with gender 1`] = `"I"`;
12 changes: 11 additions & 1 deletion 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 @@ -20,6 +20,7 @@ describe('name', () => {
'gender',
'prefix',
'sex',
'sexType',
'suffix'
)((t) => t.it('noArgs').it('with gender', 'male'));

Expand Down Expand Up @@ -365,6 +366,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

0 comments on commit 4952b22

Please sign in to comment.