Skip to content

Commit f684a14

Browse files
authored
feat(name): add sexType method (#1289)
1 parent 23adcc0 commit f684a14

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/modules/name/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,16 @@ export class Name {
284284
return this.faker.helpers.arrayElement(this.faker.definitions.name.sex);
285285
}
286286

287+
/**
288+
* Returns a random sex type.
289+
*
290+
* @example
291+
* faker.name.sexType() // Sex.Female
292+
*/
293+
sexType(): SexType {
294+
return this.faker.helpers.objectValue(Sex);
295+
}
296+
287297
/**
288298
* Returns a random name prefix.
289299
*

test/__snapshots__/name.spec.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ exports[`name > 42 > sex > noArgs 1`] = `"female"`;
5454

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

57+
exports[`name > 42 > sexType 1`] = `"female"`;
58+
5759
exports[`name > 42 > suffix > noArgs 1`] = `"III"`;
5860

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

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

117+
exports[`name > 1211 > sexType 1`] = `"male"`;
118+
115119
exports[`name > 1211 > suffix > noArgs 1`] = `"DVM"`;
116120

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

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

177+
exports[`name > 1337 > sexType 1`] = `"female"`;
178+
173179
exports[`name > 1337 > suffix > noArgs 1`] = `"I"`;
174180

175181
exports[`name > 1337 > suffix > with gender 1`] = `"I"`;

test/name.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2-
import { faker } from '../src';
2+
import { faker, Sex } from '../src';
33
import { seededTests } from './support/seededRuns';
44

55
const NON_SEEDED_BASED_RUN = 5;
@@ -11,7 +11,7 @@ describe('name', () => {
1111
});
1212

1313
seededTests(faker, 'name', (t) => {
14-
t.itEach('jobTitle', 'jobDescriptor', 'jobArea', 'jobType');
14+
t.itEach('sexType', 'jobTitle', 'jobDescriptor', 'jobArea', 'jobType');
1515

1616
t.describeEach(
1717
'firstName',
@@ -365,6 +365,15 @@ describe('name', () => {
365365
});
366366
});
367367

368+
describe('sexType()', () => {
369+
it('should return a sex type', () => {
370+
const sexType = faker.name.sexType();
371+
372+
expect(sexType).toBeTypeOf('string');
373+
expect(Object.values(Sex)).toContain(sexType);
374+
});
375+
});
376+
368377
describe('prefix()', () => {
369378
beforeEach(() => {
370379
faker.locale = 'en';

0 commit comments

Comments
 (0)