Skip to content

Commit

Permalink
feat(person): add zodiacSign method
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT committed Nov 3, 2022
1 parent 05e9844 commit 657c6a6
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/definitions/person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export type PersonDefinitions = LocaleEntry<{
name: string[];

title: PersonTitleDefinitions;

western_zodiac_sign: string[];
}>;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en/person/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import prefix from './prefix';
import sex from './sex';
import suffix from './suffix';
import title from './title';
import western_zodiac_sign from './western_zodiac_sign';

const person: PersonDefinitions = {
female_first_name,
Expand All @@ -31,6 +32,7 @@ const person: PersonDefinitions = {
sex,
suffix,
title,
western_zodiac_sign,
};

export default person;
14 changes: 14 additions & 0 deletions src/locales/en/person/western_zodiac_sign.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default [
'Aquarius',
'Pisces',
'Aries',
'Taurus',
'Gemini',
'Cancer',
'Leo',
'Virgo',
'Libra',
'Scorpio',
'Sagittarius',
'Capricorn',
];
14 changes: 14 additions & 0 deletions src/modules/person/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,18 @@ export class PersonModule {
this.faker.definitions.person.title.job
);
}

/**
* Returns a random zodiac sign.
*
* @example
* faker.person.zodiacSign() // 'Pisces'
*
* @since 8.0.0
*/
zodiacSign(): string {
return this.faker.helpers.arrayElement(
this.faker.definitions.person.western_zodiac_sign
);
}
}
6 changes: 6 additions & 0 deletions test/__snapshots__/person.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ exports[`person > 42 > suffix > noArgs 1`] = `"III"`;

exports[`person > 42 > suffix > with sex 1`] = `"III"`;

exports[`person > 42 > zodiacSign 1`] = `"Gemini"`;

exports[`person > 1211 > firstName > noArgs 1`] = `"Tito"`;

exports[`person > 1211 > firstName > with sex 1`] = `"Percy"`;
Expand Down Expand Up @@ -92,6 +94,8 @@ exports[`person > 1211 > suffix > noArgs 1`] = `"DVM"`;

exports[`person > 1211 > suffix > with sex 1`] = `"DVM"`;

exports[`person > 1211 > zodiacSign 1`] = `"Capricorn"`;

exports[`person > 1337 > firstName > noArgs 1`] = `"Devyn"`;

exports[`person > 1337 > firstName > with sex 1`] = `"Ray"`;
Expand Down Expand Up @@ -137,3 +141,5 @@ exports[`person > 1337 > sexType 1`] = `"female"`;
exports[`person > 1337 > suffix > noArgs 1`] = `"I"`;

exports[`person > 1337 > suffix > with sex 1`] = `"I"`;

exports[`person > 1337 > zodiacSign 1`] = `"Taurus"`;
12 changes: 12 additions & 0 deletions test/person.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ describe('person', () => {
sex: 'female',
});
});

t.it('zodiacSign');
});

describe(`random seeded tests for seed ${faker.seed()}`, () => {
Expand Down Expand Up @@ -382,6 +384,16 @@ describe('person', () => {
expect(faker.definitions.person.title.job).toContain(job);
});
});

describe('zodiacSign()', () => {
it('returns a random zodiac sign', () => {
const sign = faker.person.zodiacSign();

expect(sign).toBeTypeOf('string');

expect(faker.definitions.person.western_zodiac_sign).toContain(sign);
});
});
}
});
});

0 comments on commit 657c6a6

Please sign in to comment.