diff options
| author | Leyla Jähnig <[email protected]> | 2022-10-16 23:26:46 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-10-16 23:26:46 +0200 |
| commit | dac6be39fec509965e850ae1a47770c9224196f5 (patch) | |
| tree | e801a061242a9e62df84025127c362ab1c7e9c49 /test | |
| parent | 20f2236265467feb095cce5b5735bbadc07b9696 (diff) | |
| download | faker-dac6be39fec509965e850ae1a47770c9224196f5.tar.xz faker-dac6be39fec509965e850ae1a47770c9224196f5.zip | |
feat(location)!: `latitude`/`longitude` returns number (#1064)
Diffstat (limited to 'test')
| -rw-r--r-- | test/__snapshots__/address.spec.ts.snap | 12 | ||||
| -rw-r--r-- | test/address.spec.ts | 108 |
2 files changed, 50 insertions, 70 deletions
diff --git a/test/__snapshots__/address.spec.ts.snap b/test/__snapshots__/address.spec.ts.snap index dd489d6d..5099cf47 100644 --- a/test/__snapshots__/address.spec.ts.snap +++ b/test/__snapshots__/address.spec.ts.snap @@ -28,9 +28,9 @@ exports[`address > 42 > direction > with abbr = false 1`] = `"South"`; exports[`address > 42 > direction > with abbr = true 1`] = `"S"`; -exports[`address > 42 > latitude > noArgs 1`] = `"-22.5828"`; +exports[`address > 42 > latitude > noArgs 1`] = `-22.5828`; -exports[`address > 42 > longitude > noArgs 1`] = `"-45.1656"`; +exports[`address > 42 > longitude > noArgs 1`] = `-45.1656`; exports[`address > 42 > nearbyGPSCoordinate > near origin 1`] = ` [ @@ -106,9 +106,9 @@ exports[`address > 1211 > direction > with abbr = false 1`] = `"Southwest"`; exports[`address > 1211 > direction > with abbr = true 1`] = `"SW"`; -exports[`address > 1211 > latitude > noArgs 1`] = `"77.1337"`; +exports[`address > 1211 > latitude > noArgs 1`] = `77.1337`; -exports[`address > 1211 > longitude > noArgs 1`] = `"154.2673"`; +exports[`address > 1211 > longitude > noArgs 1`] = `154.2673`; exports[`address > 1211 > nearbyGPSCoordinate > near origin 1`] = ` [ @@ -184,9 +184,9 @@ exports[`address > 1337 > direction > with abbr = false 1`] = `"South"`; exports[`address > 1337 > direction > with abbr = true 1`] = `"S"`; -exports[`address > 1337 > latitude > noArgs 1`] = `"-42.8356"`; +exports[`address > 1337 > latitude > noArgs 1`] = `-42.8356`; -exports[`address > 1337 > longitude > noArgs 1`] = `"-85.6711"`; +exports[`address > 1337 > longitude > noArgs 1`] = `-85.6711`; exports[`address > 1337 > nearbyGPSCoordinate > near origin 1`] = ` [ diff --git a/test/address.spec.ts b/test/address.spec.ts index 3bee6714..ac966e90 100644 --- a/test/address.spec.ts +++ b/test/address.spec.ts @@ -153,100 +153,80 @@ describe('address', () => { }); describe('latitude()', () => { - it('returns random latitude', () => { - for (let i = 0; i < 100; i++) { - const latitude = faker.address.latitude(); + it('returns a number', () => { + const latitude = faker.address.latitude(); - expect(latitude).toBeTypeOf('string'); + expect(latitude).toBeTypeOf('number'); + }); - const latitude_float = parseFloat(latitude); + it('returns random latitude', () => { + const latitude = faker.address.latitude(); - expect(latitude_float).toBeGreaterThanOrEqual(-90.0); - expect(latitude_float).toBeLessThanOrEqual(90.0); - } + expect(latitude).toBeGreaterThanOrEqual(-90.0); + expect(latitude).toBeLessThanOrEqual(90.0); }); it('returns latitude with min and max and default precision', () => { - for (let i = 0; i < 100; i++) { - const latitude = faker.address.latitude(5, -5); - - expect(latitude).toBeTypeOf('string'); - expect( - latitude.split('.')[1].length, - 'The precision of latitude should be 4 digits' - ).toBe(4); + const latitude = faker.address.latitude(5, -5); - const latitude_float = parseFloat(latitude); + expect( + latitude.toString().split('.')[1].length, + 'The precision of latitude should be 4 digits' + ).lessThanOrEqual(4); - expect(latitude_float).toBeGreaterThanOrEqual(-5); - expect(latitude_float).toBeLessThanOrEqual(5); - } + expect(latitude).toBeGreaterThanOrEqual(-5); + expect(latitude).toBeLessThanOrEqual(5); }); it('returns random latitude with custom precision', () => { - for (let i = 0; i < 100; i++) { - const latitude = faker.address.latitude(undefined, undefined, 7); - - expect(latitude).toBeTypeOf('string'); - expect( - latitude.split('.')[1].length, - 'The precision of latitude should be 7 digits' - ).toBe(7); + const latitude = faker.address.latitude(undefined, undefined, 7); - const latitude_float = parseFloat(latitude); + expect( + latitude.toString().split('.')[1].length, + 'The precision of latitude should be 7 digits' + ).lessThanOrEqual(7); - expect(latitude_float).toBeGreaterThanOrEqual(-180); - expect(latitude_float).toBeLessThanOrEqual(180); - } + expect(latitude).toBeGreaterThanOrEqual(-180); + expect(latitude).toBeLessThanOrEqual(180); }); }); describe('longitude()', () => { - it('returns random longitude', () => { - for (let i = 0; i < 100; i++) { - const longitude = faker.address.longitude(); + it('returns a number', () => { + const longitude = faker.address.longitude(); - expect(longitude).toBeTypeOf('string'); + expect(longitude).toBeTypeOf('number'); + }); - const longitude_float = parseFloat(longitude); + it('returns random longitude', () => { + const longitude = faker.address.longitude(); - expect(longitude_float).toBeGreaterThanOrEqual(-180); - expect(longitude_float).toBeLessThanOrEqual(180); - } + expect(longitude).toBeGreaterThanOrEqual(-180); + expect(longitude).toBeLessThanOrEqual(180); }); it('returns random longitude with min and max and default precision', () => { - for (let i = 0; i < 100; i++) { - const longitude = faker.address.longitude(100, -30); - - expect(longitude).toBeTypeOf('string'); - expect( - longitude.split('.')[1].length, - 'The precision of longitude should be 4 digits' - ).toBe(4); + const longitude = faker.address.longitude(100, -30); - const longitude_float = parseFloat(longitude); + expect( + longitude.toString().split('.')[1].length, + 'The precision of longitude should be 4 digits' + ).lessThanOrEqual(4); - expect(longitude_float).toBeGreaterThanOrEqual(-30); - expect(longitude_float).toBeLessThanOrEqual(100); - } + expect(longitude).toBeGreaterThanOrEqual(-30); + expect(longitude).toBeLessThanOrEqual(100); }); it('returns random longitude with custom precision', () => { - for (let i = 0; i < 100; i++) { - const longitude = faker.address.longitude(undefined, undefined, 7); - - expect(longitude).toBeTypeOf('string'); - expect( - longitude.split('.')[1].length, - 'The precision of longitude should be 7 digits' - ).toBe(7); + const longitude = faker.address.longitude(undefined, undefined, 7); - const longitude_float = parseFloat(longitude); + expect( + longitude.toString().split('.')[1].length, + 'The precision of longitude should be 7 digits' + ).lessThanOrEqual(7); - expect(longitude_float).toBeGreaterThanOrEqual(-180); - expect(longitude_float).toBeLessThanOrEqual(180); - } + expect(longitude).toBeGreaterThanOrEqual(-180); + expect(longitude).toBeLessThanOrEqual(180); }); }); |
