diff --git a/src/ParseGeoPoint.js b/src/ParseGeoPoint.js index 1e9515058..05db0858f 100644 --- a/src/ParseGeoPoint.js +++ b/src/ParseGeoPoint.js @@ -53,7 +53,7 @@ class ParseGeoPoint { ParseGeoPoint._validate(arg1.latitude, arg1.longitude); this._latitude = arg1.latitude; this._longitude = arg1.longitude; - } else if (typeof arg1 === 'number' && typeof arg2 === 'number') { + } else if (arg1 !== undefined && arg2 !== undefined) { ParseGeoPoint._validate(arg1, arg2); this._latitude = arg1; this._longitude = arg2; @@ -163,7 +163,10 @@ class ParseGeoPoint { * Throws an exception if the given lat-long is out of bounds. */ static _validate(latitude: number, longitude: number) { - if (latitude !== latitude || longitude !== longitude) { + if ( + isNaN(latitude) || isNaN(longitude) || + typeof latitude !== 'number' || typeof longitude !== 'number' + ) { throw new TypeError( 'GeoPoint latitude and longitude must be valid numbers' ); diff --git a/src/__tests__/ParseGeoPoint-test.js b/src/__tests__/ParseGeoPoint-test.js index 8f0903e0f..b28191d55 100644 --- a/src/__tests__/ParseGeoPoint-test.js +++ b/src/__tests__/ParseGeoPoint-test.js @@ -30,14 +30,27 @@ describe('GeoPoint', () => { expect(point.longitude).toBe(88); }); - it('throws when created with NaN values', () => { - expect(function() { - new ParseGeoPoint(NaN, NaN); - }).toThrow('GeoPoint latitude and longitude must be valid numbers'); + it('throws when created with non numbers values', () => { + [ + [NaN, NaN], + [false, true], + ["29", "10"], + [29, "10"], + ["29", 10], + [["29", "10"]], + [{ latitude: "29", longitude: "10" }], + ].forEach(case_test => { + expect(function() { + new ParseGeoPoint(...case_test); + }).toThrow('GeoPoint latitude and longitude must be valid numbers'); + }); }); it('can set latitude and longitude', () => { const point = new ParseGeoPoint(); + expect(point.latitude).toBe(0); + expect(point.longitude).toBe(0); + point.latitude = 5.5; expect(point.latitude).toBe(5.5);