From db6c1b833be059f0ef23686960babc62e4dba664 Mon Sep 17 00:00:00 2001 From: Erin Millard Date: Wed, 16 Aug 2023 10:37:33 +1000 Subject: [PATCH] Reorganize getCurrentPosition() tests --- .../geolocation/get-current-position.spec.ts | 644 +++++++++--------- 1 file changed, 336 insertions(+), 308 deletions(-) diff --git a/test/jest/geolocation/get-current-position.spec.ts b/test/jest/geolocation/get-current-position.spec.ts index a47d2e7..612ff48 100644 --- a/test/jest/geolocation/get-current-position.spec.ts +++ b/test/jest/geolocation/get-current-position.spec.ts @@ -55,117 +55,60 @@ describe("Geolocation.getCurrentPosition()", () => { let errorFn: jest.Mock; beforeEach(() => { - locationServices = createLocationServices(); - geolocation = createGeolocation({ locationServices }); - successFn = jest.fn(); errorFn = jest.fn(); }); - describe("when reading the position will result in an error", () => { - beforeEach(() => { - locationServices.setPermissionState(DENIED); - }); + describe("when there is a permission request handler", () => { + let handlePermissionRequest: jest.Mock; - describe("when reading the position with an error callback", () => { - beforeEach(async () => { - await getCurrentPosition(geolocation, successFn, errorFn); - }); - - it("calls the error callback with a GeolocationPositionError", () => { - expect(errorFn).toHaveBeenCalled(); - expect(errorFn.mock.calls[0][0]).toBeDefined(); - - const error = errorFn.mock.calls[0][0] as GeolocationPositionError; - - expect(error).toBeInstanceOf(GeolocationPositionError); - }); - - it("does not call the success callback", () => { - expect(successFn).not.toHaveBeenCalled(); + beforeEach(async () => { + handlePermissionRequest = jest.fn(); + locationServices = createLocationServices({ + handlePermissionRequest, }); + geolocation = createGeolocation({ locationServices }); }); - describe("when reading the position without an error callback", () => { - beforeEach(async () => { - await getCurrentPosition( - geolocation, - successFn, - undefined, - undefined, - AbortSignal.timeout(10), - ); - }); - - it("does not call the success callback", () => { - expect(successFn).not.toHaveBeenCalled(); - }); - }); - }); - - describe("when permission is denied", () => { - beforeEach(() => { - locationServices.setPermissionState(DENIED); - }); - - describe("when reading the position", () => { - beforeEach(async () => { - await getCurrentPosition(geolocation, successFn, errorFn); - }); - - it("calls the error callback with a GeolocationPositionError with a code of PERMISSION_DENIED and an empty message", () => { - expect(errorFn).toHaveBeenCalled(); - expect(errorFn.mock.calls[0][0]).toBeDefined(); - - const error = errorFn.mock.calls[0][0] as GeolocationPositionError; - - expect(error).toBeInstanceOf(GeolocationPositionError); - expect(error.code).toBe(GeolocationPositionError.PERMISSION_DENIED); - expect(error.message).toBe(""); + describe("when permission has not been requested", () => { + beforeEach(() => { + locationServices.setPermissionState(PROMPT); }); - it("does not call the success callback", () => { - expect(successFn).not.toHaveBeenCalled(); - }); - }); + describe("when the permission request handler does not change the state", () => { + beforeEach(() => { + handlePermissionRequest.mockImplementation( + async (): Promise => PROMPT, + ); + }); - describe("when there is a permission request handler", () => { - let handlePermissionRequest: jest.Mock; + describe("when reading the position", () => { + beforeEach(async () => { + await getCurrentPosition(geolocation, successFn, errorFn); + }); - beforeEach(async () => { - handlePermissionRequest = jest.fn(); - locationServices = createLocationServices({ - handlePermissionRequest, - }); - geolocation = createGeolocation({ locationServices }); + it("calls the error callback with a GeolocationPositionError with a code of PERMISSION_DENIED and an empty message", () => { + expect(errorFn).toHaveBeenCalled(); + expect(errorFn.mock.calls[0][0]).toBeDefined(); - locationServices.setPermissionState(DENIED); - }); + const error = errorFn.mock.calls[0][0] as GeolocationPositionError; - describe("when reading the position", () => { - beforeEach(async () => { - await getCurrentPosition(geolocation, successFn, errorFn); - }); + expect(error).toBeInstanceOf(GeolocationPositionError); + expect(error.code).toBe(GeolocationPositionError.PERMISSION_DENIED); + expect(error.message).toBe(""); + }); - it("does not call the permission request handler", () => { - expect(handlePermissionRequest).not.toHaveBeenCalled(); + it("does not call the success callback", () => { + expect(successFn).not.toHaveBeenCalled(); + }); }); }); - }); - }); - - describe("when permission is granted", () => { - beforeEach(() => { - locationServices.setPermissionState(GRANTED); - }); - - describe("when location services throws an error", () => { - describe("when the error is a GeolocationPositionError", () => { - let error: StdGeolocationPositionError; + describe("when the permission request handler denies the permission", () => { beforeEach(() => { - error = createPositionUnavailableError(""); - jest.spyOn(locationServices, "getPosition").mockRejectedValue(error); + handlePermissionRequest.mockImplementation( + async (): Promise => DENIED, + ); }); describe("when reading the position", () => { @@ -173,45 +116,85 @@ describe("Geolocation.getCurrentPosition()", () => { await getCurrentPosition(geolocation, successFn, errorFn); }); - it("calls the error callback with the same error", () => { + it("calls the error callback with a GeolocationPositionError with a code of PERMISSION_DENIED and an empty message", () => { expect(errorFn).toHaveBeenCalled(); - expect(errorFn.mock.calls[0][0]).toBe(error); + expect(errorFn.mock.calls[0][0]).toBeDefined(); + + const error = errorFn.mock.calls[0][0] as GeolocationPositionError; + + expect(error).toBeInstanceOf(GeolocationPositionError); + expect(error.code).toBe(GeolocationPositionError.PERMISSION_DENIED); + expect(error.message).toBe(""); + }); + + it("does not call the success callback", () => { + expect(successFn).not.toHaveBeenCalled(); }); }); }); - describe("when the error is not a GeolocationPositionError", () => { - let error: Error; - + describe("when then permission request handler grants the permission", () => { beforeEach(() => { - error = new Error(""); - jest.spyOn(locationServices, "getPosition").mockRejectedValue(error); + handlePermissionRequest.mockImplementation( + async (): Promise => GRANTED, + ); }); - describe("when reading the position", () => { - beforeEach(async () => { - await getCurrentPosition(geolocation, successFn, errorFn); + describe("when there is no position", () => { + beforeEach(() => { + locationServices.setPosition(undefined); }); - it("calls the error callback with a GeolocationPositionError with a code of POSITION_UNAVAILABLE and includes the original message", () => { - expect(errorFn).toHaveBeenCalled(); - expect(errorFn.mock.calls[0][0]).toBeDefined(); + describe("when reading the position", () => { + beforeEach(async () => { + await getCurrentPosition(geolocation, successFn, errorFn); + }); - const error = errorFn.mock.calls[0][0] as GeolocationPositionError; + it("calls the error callback with a GeolocationPositionError with a code of POSITION_UNAVAILABLE and an empty message", () => { + expect(errorFn).toHaveBeenCalled(); + expect(errorFn.mock.calls[0][0]).toBeDefined(); - expect(error).toBeInstanceOf(GeolocationPositionError); - expect(error.code).toBe( - GeolocationPositionError.POSITION_UNAVAILABLE, - ); - expect(error.message).toBe("Location services error: "); + const error = errorFn.mock + .calls[0][0] as GeolocationPositionError; + + expect(error).toBeInstanceOf(GeolocationPositionError); + expect(error.code).toBe( + GeolocationPositionError.POSITION_UNAVAILABLE, + ); + expect(error.message).toBe(""); + }); + + it("does not call the success callback", () => { + expect(successFn).not.toHaveBeenCalled(); + }); + }); + }); + + describe("when there is a position", () => { + beforeEach(() => { + locationServices.setPosition(positionA); + }); + + describe("when reading the position", () => { + beforeEach(async () => { + await getCurrentPosition(geolocation, successFn, errorFn); + }); + + it("calls the success callback with the position", () => { + expect(successFn).toHaveBeenCalledWith(positionA); + }); + + it("does not call the error callback", () => { + expect(errorFn).not.toHaveBeenCalled(); + }); }); }); }); }); - describe("when there is no position", () => { + describe("when permission is denied", () => { beforeEach(() => { - locationServices.setPosition(undefined); + locationServices.setPermissionState(DENIED); }); describe("when reading the position", () => { @@ -219,16 +202,18 @@ describe("Geolocation.getCurrentPosition()", () => { await getCurrentPosition(geolocation, successFn, errorFn); }); - it("calls the error callback with a GeolocationPositionError with a code of POSITION_UNAVAILABLE and an empty message", () => { + it("does not call the permission request handler", () => { + expect(handlePermissionRequest).not.toHaveBeenCalled(); + }); + + it("calls the error callback with a GeolocationPositionError with a code of PERMISSION_DENIED and an empty message", () => { expect(errorFn).toHaveBeenCalled(); expect(errorFn.mock.calls[0][0]).toBeDefined(); const error = errorFn.mock.calls[0][0] as GeolocationPositionError; expect(error).toBeInstanceOf(GeolocationPositionError); - expect(error.code).toBe( - GeolocationPositionError.POSITION_UNAVAILABLE, - ); + expect(error.code).toBe(GeolocationPositionError.PERMISSION_DENIED); expect(error.message).toBe(""); }); @@ -238,37 +223,111 @@ describe("Geolocation.getCurrentPosition()", () => { }); }); - describe("when there is a position", () => { + describe("when permission is granted", () => { beforeEach(() => { - locationServices.setPosition(positionA); + locationServices.setPermissionState(GRANTED); }); - it("cannot be read synchronously", () => { - let position: StdGeolocationPosition | undefined; - geolocation.getCurrentPosition((nextPosition) => { - position = nextPosition; + describe("when location services throws an error", () => { + describe("when the error is a GeolocationPositionError", () => { + let error: StdGeolocationPositionError; + + beforeEach(() => { + error = createPositionUnavailableError(""); + jest + .spyOn(locationServices, "getPosition") + .mockRejectedValue(error); + }); + + describe("when reading the position", () => { + beforeEach(async () => { + await getCurrentPosition(geolocation, successFn, errorFn); + }); + + it("calls the error callback with the same error", () => { + expect(errorFn).toHaveBeenCalled(); + expect(errorFn.mock.calls[0][0]).toBe(error); + }); + }); }); - expect(position).toBeUndefined(); - }); + describe("when the error is not a GeolocationPositionError", () => { + let error: Error; - describe("when reading the position", () => { - beforeEach(async () => { - await getCurrentPosition(geolocation, successFn, errorFn); + beforeEach(() => { + error = new Error(""); + jest + .spyOn(locationServices, "getPosition") + .mockRejectedValue(error); + }); + + describe("when reading the position", () => { + beforeEach(async () => { + await getCurrentPosition(geolocation, successFn, errorFn); + }); + + it("calls the error callback with a GeolocationPositionError with a code of POSITION_UNAVAILABLE and includes the original message", () => { + expect(errorFn).toHaveBeenCalled(); + expect(errorFn.mock.calls[0][0]).toBeDefined(); + + const error = errorFn.mock + .calls[0][0] as GeolocationPositionError; + + expect(error).toBeInstanceOf(GeolocationPositionError); + expect(error.code).toBe( + GeolocationPositionError.POSITION_UNAVAILABLE, + ); + expect(error.message).toBe("Location services error: "); + }); + }); }); + }); - it("calls the success callback with the position", () => { - expect(successFn).toHaveBeenCalledWith(positionA); + describe("when there is no position", () => { + beforeEach(() => { + locationServices.setPosition(undefined); }); - it("does not call the error callback", () => { - expect(errorFn).not.toHaveBeenCalled(); + describe("when reading the position", () => { + beforeEach(async () => { + await getCurrentPosition(geolocation, successFn, errorFn); + }); + + it("does not call the permission request handler", () => { + expect(handlePermissionRequest).not.toHaveBeenCalled(); + }); + + it("calls the error callback with a GeolocationPositionError with a code of POSITION_UNAVAILABLE and an empty message", () => { + expect(errorFn).toHaveBeenCalled(); + expect(errorFn.mock.calls[0][0]).toBeDefined(); + + const error = errorFn.mock.calls[0][0] as GeolocationPositionError; + + expect(error).toBeInstanceOf(GeolocationPositionError); + expect(error.code).toBe( + GeolocationPositionError.POSITION_UNAVAILABLE, + ); + expect(error.message).toBe(""); + }); + + it("does not call the success callback", () => { + expect(successFn).not.toHaveBeenCalled(); + }); }); }); - describe("when the position changes", () => { + describe("when there is a position", () => { beforeEach(() => { - locationServices.setPosition(positionB); + locationServices.setPosition(positionA); + }); + + it("cannot be read synchronously", () => { + let position: StdGeolocationPosition | undefined; + geolocation.getCurrentPosition((nextPosition) => { + position = nextPosition; + }); + + expect(position).toBeUndefined(); }); describe("when reading the position", () => { @@ -276,134 +335,162 @@ describe("Geolocation.getCurrentPosition()", () => { await getCurrentPosition(geolocation, successFn, errorFn); }); - it("calls the success callback with the new position", () => { - expect(successFn).toHaveBeenCalledWith(positionB); + it("does not call the permission request handler", () => { + expect(handlePermissionRequest).not.toHaveBeenCalled(); + }); + + it("calls the success callback with the position", () => { + expect(successFn).toHaveBeenCalledWith(positionA); }); it("does not call the error callback", () => { expect(errorFn).not.toHaveBeenCalled(); }); }); + + describe("when the position changes", () => { + beforeEach(() => { + locationServices.setPosition(positionB); + }); + + describe("when reading the position", () => { + beforeEach(async () => { + await getCurrentPosition(geolocation, successFn, errorFn); + }); + + it("calls the success callback with the new position", () => { + expect(successFn).toHaveBeenCalledWith(positionB); + }); + + it("does not call the error callback", () => { + expect(errorFn).not.toHaveBeenCalled(); + }); + }); + }); }); - }); - describe("when reading the position with a timeout", () => { - describe("when the timeout is not exceeded", () => { - describe("when there is a position", () => { - beforeEach(async () => { - locationServices.setPosition(positionA); + describe("when reading the position with a timeout", () => { + describe("when the timeout is not exceeded", () => { + describe("when there is a position", () => { + beforeEach(async () => { + locationServices.setPosition(positionA); - await getCurrentPosition(geolocation, successFn, errorFn, { - timeout: 1000, + await getCurrentPosition(geolocation, successFn, errorFn, { + timeout: 1000, + }); + }); + + it("calls the success callback with the position", () => { + expect(successFn).toHaveBeenCalledWith(positionA); }); }); - it("calls the success callback with the position", () => { - expect(successFn).toHaveBeenCalledWith(positionA); + describe("when there is no position", () => { + beforeEach(async () => { + locationServices.setPosition(undefined); + + await getCurrentPosition(geolocation, successFn, errorFn, { + timeout: 1000, + }); + }); + + it("calls the error callback with a GeolocationPositionError with a code of POSITION_UNAVAILABLE and an empty message", async () => { + expect(errorFn).toHaveBeenCalled(); + expect(errorFn.mock.calls[0][0]).toBeDefined(); + + const error = errorFn.mock + .calls[0][0] as GeolocationPositionError; + + expect(error).toBeInstanceOf(GeolocationPositionError); + expect(error.code).toBe( + GeolocationPositionError.POSITION_UNAVAILABLE, + ); + expect(error.message).toBe(""); + }); }); }); - describe("when there is no position", () => { + describe("when the timeout is exceeded", () => { beforeEach(async () => { - locationServices.setPosition(undefined); + locationServices.setPosition(positionA); await getCurrentPosition(geolocation, successFn, errorFn, { - timeout: 1000, + timeout: 0, }); }); - it("calls the error callback with a GeolocationPositionError with a code of POSITION_UNAVAILABLE and an empty message", async () => { + it("calls the error callback with a GeolocationPositionError with a code of TIMEOUT and an empty message", () => { expect(errorFn).toHaveBeenCalled(); expect(errorFn.mock.calls[0][0]).toBeDefined(); const error = errorFn.mock.calls[0][0] as GeolocationPositionError; expect(error).toBeInstanceOf(GeolocationPositionError); - expect(error.code).toBe( - GeolocationPositionError.POSITION_UNAVAILABLE, - ); + expect(error.code).toBe(GeolocationPositionError.TIMEOUT); expect(error.message).toBe(""); }); }); - }); - describe("when the timeout is exceeded", () => { - beforeEach(async () => { - locationServices.setPosition(positionA); + describe("when the timeout is negative", () => { + beforeEach(async () => { + locationServices.setPosition(positionA); - await getCurrentPosition(geolocation, successFn, errorFn, { - timeout: 0, + await getCurrentPosition(geolocation, successFn, errorFn, { + timeout: -1, + }); }); - }); - it("calls the error callback with a GeolocationPositionError with a code of TIMEOUT and an empty message", () => { - expect(errorFn).toHaveBeenCalled(); - expect(errorFn.mock.calls[0][0]).toBeDefined(); + it("calls the error callback with a GeolocationPositionError with a code of TIMEOUT and an empty message", () => { + expect(errorFn).toHaveBeenCalled(); + expect(errorFn.mock.calls[0][0]).toBeDefined(); - const error = errorFn.mock.calls[0][0] as GeolocationPositionError; + const error = errorFn.mock.calls[0][0] as GeolocationPositionError; - expect(error).toBeInstanceOf(GeolocationPositionError); - expect(error.code).toBe(GeolocationPositionError.TIMEOUT); - expect(error.message).toBe(""); + expect(error).toBeInstanceOf(GeolocationPositionError); + expect(error.code).toBe(GeolocationPositionError.TIMEOUT); + expect(error.message).toBe(""); + }); }); }); + }); + }); - describe("when the timeout is negative", () => { - beforeEach(async () => { - locationServices.setPosition(positionA); + describe("when there is no permission request handler", () => { + beforeEach(async () => { + locationServices = createLocationServices(); + geolocation = createGeolocation({ locationServices }); + }); - await getCurrentPosition(geolocation, successFn, errorFn, { - timeout: -1, - }); + describe("when permission has not been requested", () => { + beforeEach(() => { + locationServices.setPermissionState(PROMPT); + }); + + describe("when reading the position", () => { + beforeEach(async () => { + await getCurrentPosition(geolocation, successFn, errorFn); }); - it("calls the error callback with a GeolocationPositionError with a code of TIMEOUT and an empty message", () => { + it("calls the error callback with a GeolocationPositionError with a code of PERMISSION_DENIED and an empty message", () => { expect(errorFn).toHaveBeenCalled(); expect(errorFn.mock.calls[0][0]).toBeDefined(); const error = errorFn.mock.calls[0][0] as GeolocationPositionError; expect(error).toBeInstanceOf(GeolocationPositionError); - expect(error.code).toBe(GeolocationPositionError.TIMEOUT); + expect(error.code).toBe(GeolocationPositionError.PERMISSION_DENIED); expect(error.message).toBe(""); }); - }); - }); - describe("when there is a permission request handler", () => { - let handlePermissionRequest: jest.Mock; - - beforeEach(async () => { - handlePermissionRequest = jest.fn(); - locationServices = createLocationServices({ - handlePermissionRequest, - }); - geolocation = createGeolocation({ locationServices }); - - locationServices.setPermissionState(GRANTED); - }); - - describe("when reading the position", () => { - beforeEach(async () => { - await getCurrentPosition(geolocation, successFn, errorFn); - }); - - it("does not call the permission request handler", () => { - expect(handlePermissionRequest).not.toHaveBeenCalled(); + it("does not call the success callback", () => { + expect(successFn).not.toHaveBeenCalled(); }); }); }); - }); - - describe("when permission has not been requested", () => { - beforeEach(() => { - locationServices.setPermissionState(PROMPT); - }); - describe("when there is no permission request handler", () => { - beforeEach(async () => { - locationServices = createLocationServices(); - geolocation = createGeolocation({ locationServices }); + describe("when permission is denied", () => { + beforeEach(() => { + locationServices.setPermissionState(DENIED); }); describe("when reading the position", () => { @@ -428,22 +515,14 @@ describe("Geolocation.getCurrentPosition()", () => { }); }); - describe("when there is a permission request handler", () => { - let handlePermissionRequest: jest.Mock; - - beforeEach(async () => { - handlePermissionRequest = jest.fn(); - locationServices = createLocationServices({ - handlePermissionRequest, - }); - geolocation = createGeolocation({ locationServices }); + describe("when permission is granted", () => { + beforeEach(() => { + locationServices.setPermissionState(GRANTED); }); - describe("when the permission request handler does not change the state", () => { + describe("when there is a position", () => { beforeEach(() => { - handlePermissionRequest.mockImplementation( - async (): Promise => PROMPT, - ); + locationServices.setPosition(positionA); }); describe("when reading the position", () => { @@ -451,108 +530,57 @@ describe("Geolocation.getCurrentPosition()", () => { await getCurrentPosition(geolocation, successFn, errorFn); }); - it("calls the error callback with a GeolocationPositionError with a code of PERMISSION_DENIED and an empty message", () => { - expect(errorFn).toHaveBeenCalled(); - expect(errorFn.mock.calls[0][0]).toBeDefined(); - - const error = errorFn.mock.calls[0][0] as GeolocationPositionError; - - expect(error).toBeInstanceOf(GeolocationPositionError); - expect(error.code).toBe(GeolocationPositionError.PERMISSION_DENIED); - expect(error.message).toBe(""); + it("calls the success callback with the position", () => { + expect(successFn).toHaveBeenCalledWith(positionA); }); - it("does not call the success callback", () => { - expect(successFn).not.toHaveBeenCalled(); + it("does not call the error callback", () => { + expect(errorFn).not.toHaveBeenCalled(); }); }); }); + }); + }); - describe("when the permission request handler denies the permission", () => { - beforeEach(() => { - handlePermissionRequest.mockImplementation( - async (): Promise => DENIED, - ); - }); - - describe("when reading the position", () => { - beforeEach(async () => { - await getCurrentPosition(geolocation, successFn, errorFn); - }); - - it("calls the error callback with a GeolocationPositionError with a code of PERMISSION_DENIED and an empty message", () => { - expect(errorFn).toHaveBeenCalled(); - expect(errorFn.mock.calls[0][0]).toBeDefined(); - - const error = errorFn.mock.calls[0][0] as GeolocationPositionError; - - expect(error).toBeInstanceOf(GeolocationPositionError); - expect(error.code).toBe(GeolocationPositionError.PERMISSION_DENIED); - expect(error.message).toBe(""); - }); + describe("when reading the position will result in an error", () => { + beforeEach(() => { + locationServices = createLocationServices(); + locationServices.setPermissionState(DENIED); + geolocation = createGeolocation({ locationServices }); + }); - it("does not call the success callback", () => { - expect(successFn).not.toHaveBeenCalled(); - }); - }); + describe("when reading the position with an error callback", () => { + beforeEach(async () => { + await getCurrentPosition(geolocation, successFn, errorFn); }); - describe("when then permission request handler grants the permission", () => { - beforeEach(() => { - handlePermissionRequest.mockImplementation( - async (): Promise => GRANTED, - ); - }); - - describe("when there is no position", () => { - beforeEach(() => { - locationServices.setPosition(undefined); - }); - - describe("when reading the position", () => { - beforeEach(async () => { - await getCurrentPosition(geolocation, successFn, errorFn); - }); - - it("calls the error callback with a GeolocationPositionError with a code of POSITION_UNAVAILABLE and an empty message", () => { - expect(errorFn).toHaveBeenCalled(); - expect(errorFn.mock.calls[0][0]).toBeDefined(); - - const error = errorFn.mock - .calls[0][0] as GeolocationPositionError; - - expect(error).toBeInstanceOf(GeolocationPositionError); - expect(error.code).toBe( - GeolocationPositionError.POSITION_UNAVAILABLE, - ); - expect(error.message).toBe(""); - }); + it("calls the error callback with a GeolocationPositionError", () => { + expect(errorFn).toHaveBeenCalled(); + expect(errorFn.mock.calls[0][0]).toBeDefined(); - it("does not call the success callback", () => { - expect(successFn).not.toHaveBeenCalled(); - }); - }); - }); + const error = errorFn.mock.calls[0][0] as GeolocationPositionError; - describe("when there is a position", () => { - beforeEach(() => { - locationServices.setPosition(positionA); - }); + expect(error).toBeInstanceOf(GeolocationPositionError); + }); - describe("when reading the position", () => { - beforeEach(async () => { - await getCurrentPosition(geolocation, successFn, errorFn); - }); + it("does not call the success callback", () => { + expect(successFn).not.toHaveBeenCalled(); + }); + }); - it("calls the success callback with the position", () => { - expect(successFn).toHaveBeenCalledWith(positionA); - }); + describe("when reading the position without an error callback", () => { + beforeEach(async () => { + await getCurrentPosition( + geolocation, + successFn, + undefined, + undefined, + AbortSignal.timeout(10), + ); + }); - it("does not call the error callback", () => { - expect(errorFn).not.toHaveBeenCalled(); - }); - }); - }); + it("does not call the success callback", () => { + expect(successFn).not.toHaveBeenCalled(); }); }); });