File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,6 +36,11 @@ export type LocationDefinition = LocaleEntry<{
3636 */
3737 city_suffix : string [ ] ;
3838
39+ /**
40+ * The names of all continents.
41+ */
42+ continent : string [ ] ;
43+
3944 /**
4045 * The names of all countries.
4146 */
Original file line number Diff line number Diff line change 1+ export default [
2+ 'Africa' ,
3+ 'Antarctica' ,
4+ 'Asia' ,
5+ 'Australia' ,
6+ 'Europe' ,
7+ 'North America' ,
8+ 'South America' ,
9+ ] ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import city_name from './city_name';
88import city_pattern from './city_pattern' ;
99import city_prefix from './city_prefix' ;
1010import city_suffix from './city_suffix' ;
11+ import continent from './continent' ;
1112import country from './country' ;
1213import county from './county' ;
1314import direction from './direction' ;
@@ -26,6 +27,7 @@ const location: LocationDefinition = {
2627 city_pattern,
2728 city_prefix,
2829 city_suffix,
30+ continent,
2931 country,
3032 county,
3133 direction,
Original file line number Diff line number Diff line change @@ -216,6 +216,20 @@ export class LocationModule extends ModuleBase {
216216 ) ;
217217 }
218218
219+ /**
220+ * Returns a random continent name.
221+ *
222+ * @example
223+ * faker.location.continent() // 'Asia'
224+ *
225+ * @since 9.1.0
226+ */
227+ continent ( ) : string {
228+ return this . faker . helpers . arrayElement (
229+ this . faker . definitions . location . continent
230+ ) ;
231+ }
232+
219233 /**
220234 * Returns a random [ISO_3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) country code.
221235 *
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ exports[`location > 42 > cardinalDirection > with abbreviated option 1`] = `"E"`
88
99exports [` location > 42 > city 1` ] = ` "Fort Moses"` ;
1010
11+ exports [` location > 42 > continent 1` ] = ` "Asia"` ;
12+
1113exports [` location > 42 > country 1` ] = ` "Guinea"` ;
1214
1315exports [` location > 42 > countryCode > noArgs 1` ] = ` "GY"` ;
@@ -144,6 +146,8 @@ exports[`location > 1211 > cardinalDirection > with abbreviated option 1`] = `"W
144146
145147exports [` location > 1211 > city 1` ] = ` "The Villages"` ;
146148
149+ exports [` location > 1211 > continent 1` ] = ` "South America"` ;
150+
147151exports [` location > 1211 > country 1` ] = ` "Uganda"` ;
148152
149153exports [` location > 1211 > countryCode > noArgs 1` ] = ` "UM"` ;
@@ -280,6 +284,8 @@ exports[`location > 1337 > cardinalDirection > with abbreviated option 1`] = `"E
280284
281285exports [` location > 1337 > city 1` ] = ` "East Duane"` ;
282286
287+ exports [` location > 1337 > continent 1` ] = ` "Antarctica"` ;
288+
283289exports [` location > 1337 > country 1` ] = ` "Egypt"` ;
284290
285291exports [` location > 1337 > countryCode > noArgs 1` ] = ` "EH"` ;
Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ describe('location', () => {
7777
7878 t . it ( 'country' ) ;
7979
80+ t . it ( 'continent' ) ;
81+
8082 t . describe ( 'countryCode' , ( t ) => {
8183 t . it ( 'noArgs' )
8284 . it ( 'with string alpha-2' , 'alpha-2' )
@@ -145,6 +147,16 @@ describe('location', () => {
145147 describe . each ( times ( NON_SEEDED_BASED_RUN ) . map ( ( ) => faker . seed ( ) ) ) (
146148 'random seeded tests for seed %i' ,
147149 ( ) => {
150+ describe ( 'continent()' , ( ) => {
151+ it ( 'returns random continent' , ( ) => {
152+ const actual = faker . location . continent ( ) ;
153+
154+ expect ( actual ) . toBeTruthy ( ) ;
155+ expect ( actual ) . toBeTypeOf ( 'string' ) ;
156+ expect ( faker . definitions . location . continent ) . toContain ( actual ) ;
157+ } ) ;
158+ } ) ;
159+
148160 describe ( 'countryCode()' , ( ) => {
149161 it ( 'returns random alpha-2 countryCode' , ( ) => {
150162 const countryCode = faker . location . countryCode ( 'alpha-2' ) ;
You can’t perform that action at this time.
0 commit comments