diff --git a/src/geolocation-observer.ts b/src/geolocation-observer.ts index 92ee1b0..d37d99c 100644 --- a/src/geolocation-observer.ts +++ b/src/geolocation-observer.ts @@ -78,9 +78,15 @@ export function createGeolocationObserver( nextMatcher: for (const matcher of matchers) { for (const property in matcher) { + const a = matcher[property as keyof typeof matcher]; + const b = coords[property as keyof typeof coords]; + if ( - matcher[property as keyof typeof matcher] !== - coords[property as keyof typeof coords] + a !== b && + /* v8 ignore start: can't test without another execution context */ + !(typeof a === "undefined" && typeof b === "undefined") && + /* v8 ignore stop */ + !(Number.isNaN(a) && Number.isNaN(b)) ) { continue nextMatcher; } diff --git a/test/vitest/geolocation-observer.spec.ts b/test/vitest/geolocation-observer.spec.ts index 7f69a43..51f29a8 100644 --- a/test/vitest/geolocation-observer.spec.ts +++ b/test/vitest/geolocation-observer.spec.ts @@ -244,6 +244,23 @@ describe("GeolocationObserver", () => { }); }); + describe("when called with a matcher with a NaN heading", () => { + it("resolves when the coords match", async () => { + locationServices.setLowAccuracyCoordinates({ + ...coordsA, + heading: NaN, + }); + permissionStore.setStatus({ name: "geolocation" }, "GRANTED"); + await runTaskQueue(); + const observer = createGeolocationObserver(geolocation, permissions); + await runTaskQueue(); + + await expect( + observer.waitForCoordinates({ heading: NaN }), + ).resolves.toBeUndefined(); + }); + }); + describe("when called with an async task function", () => { it("runs the task while waiting", async () => { locationServices.setLowAccuracyCoordinates(coordsA);