Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Aug 8, 2024
1 parent a3c318a commit 86e159f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ wait for specific geolocation errors by calling
import {
createAPIs,
createCoordinates,
createGeolocationObserver,
PERMISSION_DENIED,
POSITION_UNAVAILABLE,
} from "fake-geolocation";

const { geolocation, user } = createAPIs();
const { geolocation, observer, permissions, user } = createAPIs();

// We need some coords to start with
const coordsA = createCoordinates({ latitude: 1, longitude: 2 });
Expand All @@ -69,8 +68,8 @@ geolocation.watchPosition(
},
);

// Create an observer
const observer = createGeolocationObserver(geolocation);
// Start a Permissions API query
const status = await permissions.query({ name: "geolocation" });

// Wait for the position to be at coordsA
await observer.waitForCoordinates(coordsA);
Expand Down Expand Up @@ -119,6 +118,13 @@ await observer.waitForPositionError(PERMISSION_DENIED, async () => {
});
// Outputs "true"
console.log(error?.code === PERMISSION_DENIED);

// You can also wait for geolocation permission states
await observer.waitForPermissionState("granted", async () => {
user.grantPermission({ name: "geolocation" });
});
// Outputs "true"
console.log(status.state === "granted");
```

### Fixed
Expand Down

0 comments on commit 86e159f

Please sign in to comment.