aboutsummaryrefslogtreecommitdiff
path: root/test/modules/location.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/modules/location.spec.ts')
-rw-r--r--test/modules/location.spec.ts106
1 files changed, 55 insertions, 51 deletions
diff --git a/test/modules/location.spec.ts b/test/modules/location.spec.ts
index 45d789a4..7ca81672 100644
--- a/test/modules/location.spec.ts
+++ b/test/modules/location.spec.ts
@@ -8,6 +8,7 @@ import {
faker,
fakerEN_CA,
fakerEN_US,
+ simpleFaker,
} from '../../src';
import { seededTests } from '../support/seeded-runs';
import { times } from './../support/times';
@@ -247,22 +248,22 @@ describe('location', () => {
});
});
- describe('latitude()', () => {
+ describe.each([faker, simpleFaker])('latitude()', (fakerFn) => {
it('returns a number', () => {
- const latitude = faker.location.latitude();
+ const latitude = fakerFn.location.latitude();
expect(latitude).toBeTypeOf('number');
});
it('returns random latitude', () => {
- const latitude = faker.location.latitude();
+ const latitude = fakerFn.location.latitude();
expect(latitude).toBeGreaterThanOrEqual(-90.0);
expect(latitude).toBeLessThanOrEqual(90.0);
});
it('returns latitude with min and max and default precision', () => {
- const latitude = faker.location.latitude({ max: 5, min: -5 });
+ const latitude = fakerFn.location.latitude({ max: 5, min: -5 });
expect(
precision(latitude),
@@ -274,7 +275,7 @@ describe('location', () => {
});
it('returns random latitude with custom precision', () => {
- const latitude = faker.location.latitude({ precision: 7 });
+ const latitude = fakerFn.location.latitude({ precision: 7 });
expect(
precision(latitude),
@@ -286,22 +287,22 @@ describe('location', () => {
});
});
- describe('longitude()', () => {
+ describe.each([faker, simpleFaker])('longitude()', (fakerFn) => {
it('returns a number', () => {
- const longitude = faker.location.longitude();
+ const longitude = fakerFn.location.longitude();
expect(longitude).toBeTypeOf('number');
});
it('returns random longitude', () => {
- const longitude = faker.location.longitude();
+ const longitude = fakerFn.location.longitude();
expect(longitude).toBeGreaterThanOrEqual(-180);
expect(longitude).toBeLessThanOrEqual(180);
});
it('returns random longitude with min and max and default precision', () => {
- const longitude = faker.location.longitude({ max: 100, min: -30 });
+ const longitude = fakerFn.location.longitude({ max: 100, min: -30 });
expect(
precision(longitude),
@@ -313,7 +314,7 @@ describe('location', () => {
});
it('returns random longitude with custom precision', () => {
- const longitude = faker.location.longitude({ precision: 7 });
+ const longitude = fakerFn.location.longitude({ precision: 7 });
expect(
precision(longitude),
@@ -376,47 +377,50 @@ describe('location', () => {
});
});
- describe('nearbyGPSCoordinate()', () => {
- it.each(
- times(100).flatMap((radius) => [
- [{ isMetric: true, radius }],
- [{ isMetric: false, radius }],
- ])
- )(
- 'should return random gps coordinate within a distance of another one (%j)',
- ({ isMetric, radius }) => {
- const latitude1 = +faker.location.latitude();
- const longitude1 = +faker.location.longitude();
-
- const coordinate = faker.location.nearbyGPSCoordinate({
- origin: [latitude1, longitude1],
- radius,
- isMetric,
- });
-
- expect(coordinate).toHaveLength(2);
- expect(coordinate[0]).toBeTypeOf('number');
- expect(coordinate[1]).toBeTypeOf('number');
-
- const latitude2 = coordinate[0];
- expect(latitude2).toBeGreaterThanOrEqual(-90.0);
- expect(latitude2).toBeLessThanOrEqual(90.0);
-
- const longitude2 = coordinate[1];
- expect(longitude2).toBeGreaterThanOrEqual(-180.0);
- expect(longitude2).toBeLessThanOrEqual(180.0);
-
- const actualDistance = haversine(
- latitude1,
- longitude1,
- latitude2,
- longitude2,
- isMetric
- );
- expect(actualDistance).toBeLessThanOrEqual(radius);
- }
- );
- });
+ describe.each([faker, simpleFaker])(
+ 'nearbyGPSCoordinate()',
+ (fakerFn) => {
+ it.each(
+ times(100).flatMap((radius) => [
+ [{ isMetric: true, radius }],
+ [{ isMetric: false, radius }],
+ ])
+ )(
+ 'should return random gps coordinate within a distance of another one (%j)',
+ ({ isMetric, radius }) => {
+ const latitude1 = +fakerFn.location.latitude();
+ const longitude1 = +fakerFn.location.longitude();
+
+ const coordinate = fakerFn.location.nearbyGPSCoordinate({
+ origin: [latitude1, longitude1],
+ radius,
+ isMetric,
+ });
+
+ expect(coordinate).toHaveLength(2);
+ expect(coordinate[0]).toBeTypeOf('number');
+ expect(coordinate[1]).toBeTypeOf('number');
+
+ const latitude2 = coordinate[0];
+ expect(latitude2).toBeGreaterThanOrEqual(-90.0);
+ expect(latitude2).toBeLessThanOrEqual(90.0);
+
+ const longitude2 = coordinate[1];
+ expect(longitude2).toBeGreaterThanOrEqual(-180.0);
+ expect(longitude2).toBeLessThanOrEqual(180.0);
+
+ const actualDistance = haversine(
+ latitude1,
+ longitude1,
+ latitude2,
+ longitude2,
+ isMetric
+ );
+ expect(actualDistance).toBeLessThanOrEqual(radius);
+ }
+ );
+ }
+ );
describe('timeZone', () => {
it('should return a random timezone', () => {