diff --git a/src/definitions/location.ts b/src/definitions/location.ts index 5aee4e79e3f..9fbda95f59b 100644 --- a/src/definitions/location.ts +++ b/src/definitions/location.ts @@ -36,6 +36,11 @@ export type LocationDefinition = LocaleEntry<{ */ city_suffix: string[]; + /** + * The names of all continents. + */ + continent: string[]; + /** * The names of all countries. */ diff --git a/src/locales/en/location/continent.ts b/src/locales/en/location/continent.ts new file mode 100644 index 00000000000..379b460155e --- /dev/null +++ b/src/locales/en/location/continent.ts @@ -0,0 +1,9 @@ +export default [ + 'Africa', + 'Antarctica', + 'Asia', + 'Australia', + 'Europe', + 'North America', + 'South America', +]; diff --git a/src/locales/en/location/index.ts b/src/locales/en/location/index.ts index 7938321dcb7..64ca3268f7d 100644 --- a/src/locales/en/location/index.ts +++ b/src/locales/en/location/index.ts @@ -8,6 +8,7 @@ import city_name from './city_name'; import city_pattern from './city_pattern'; import city_prefix from './city_prefix'; import city_suffix from './city_suffix'; +import continent from './continent'; import country from './country'; import county from './county'; import direction from './direction'; @@ -26,6 +27,7 @@ const location: LocationDefinition = { city_pattern, city_prefix, city_suffix, + continent, country, county, direction, diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts index 4aabdd8db4a..4a49e029501 100644 --- a/src/modules/location/index.ts +++ b/src/modules/location/index.ts @@ -216,6 +216,20 @@ export class LocationModule extends ModuleBase { ); } + /** + * Returns a random continent name. + * + * @example + * faker.location.continent() // 'Asia' + * + * @since 9.1.0 + */ + continent(): string { + return this.faker.helpers.arrayElement( + this.faker.definitions.location.continent + ); + } + /** * Returns a random [ISO_3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) country code. * diff --git a/test/modules/__snapshots__/location.spec.ts.snap b/test/modules/__snapshots__/location.spec.ts.snap index b53acbda355..a8d24e9a6ef 100644 --- a/test/modules/__snapshots__/location.spec.ts.snap +++ b/test/modules/__snapshots__/location.spec.ts.snap @@ -8,6 +8,8 @@ exports[`location > 42 > cardinalDirection > with abbreviated option 1`] = `"E"` exports[`location > 42 > city 1`] = `"Fort Moses"`; +exports[`location > 42 > continent 1`] = `"Asia"`; + exports[`location > 42 > country 1`] = `"Guinea"`; exports[`location > 42 > countryCode > noArgs 1`] = `"GY"`; @@ -144,6 +146,8 @@ exports[`location > 1211 > cardinalDirection > with abbreviated option 1`] = `"W exports[`location > 1211 > city 1`] = `"The Villages"`; +exports[`location > 1211 > continent 1`] = `"South America"`; + exports[`location > 1211 > country 1`] = `"Uganda"`; exports[`location > 1211 > countryCode > noArgs 1`] = `"UM"`; @@ -280,6 +284,8 @@ exports[`location > 1337 > cardinalDirection > with abbreviated option 1`] = `"E exports[`location > 1337 > city 1`] = `"East Duane"`; +exports[`location > 1337 > continent 1`] = `"Antarctica"`; + exports[`location > 1337 > country 1`] = `"Egypt"`; exports[`location > 1337 > countryCode > noArgs 1`] = `"EH"`; diff --git a/test/modules/location.spec.ts b/test/modules/location.spec.ts index 1291efd31fd..2be7c4896a3 100644 --- a/test/modules/location.spec.ts +++ b/test/modules/location.spec.ts @@ -77,6 +77,8 @@ describe('location', () => { t.it('country'); + t.it('continent'); + t.describe('countryCode', (t) => { t.it('noArgs') .it('with string alpha-2', 'alpha-2') @@ -145,6 +147,16 @@ describe('location', () => { describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))( 'random seeded tests for seed %i', () => { + describe('continent()', () => { + it('returns random continent', () => { + const actual = faker.location.continent(); + + expect(actual).toBeTruthy(); + expect(actual).toBeTypeOf('string'); + expect(faker.definitions.location.continent).toContain(actual); + }); + }); + describe('countryCode()', () => { it('returns random alpha-2 countryCode', () => { const countryCode = faker.location.countryCode('alpha-2');