Assert and act
Retrying assertions on what the map shows, and auto-waiting, verified actions that start on the map.
Inside a Playwright test, once the page shows your app:
import { geowright, expect } from 'geowright';const map = geowright(page);// { mapId?: 'main', timeout?, ignoreLayers?, mirror?, failureScreenshots? }await map.waitForIdle();// ASSERT — retrying, like web-first assertionsawait expect(map).toHaveFeature({ layer: 'alerts', where: { severity: 'high' } });await expect(map.features({ layer: 'alerts' })).toHaveFeatureCount(3);await page.getByTestId('alert-remove-2').click();// an action in the app's normal UI...await expect(map).not.toHaveFeature({ layer: 'alerts', id: 2 });// ...and its effect on the mapawait page.getByTestId('toggle-sensors').check();await expect(map).toHaveFeature({ layer: 'sensors', id: 502 }, { visible: 'any' });// opt out: "rendered" incl. opacity-0await expect(map.feature({ layer: 'sensors', id: 501 })).toBeVisibleOnMap();// paint and pixelsawait page.getByTestId('fly-east').click();await expect(map).toHaveView({ center: { lng: 35.2, lat: 32.08 }, zoom: 12 });// once the camera is at rest// ACT — auto-waiting, strict, verifiedawait map.feature({ layer: 'alerts', id: 4 }).click();await map.feature({ layer: 'parcels', id: 103 }).click({ autoPan: true });// off-screen: map's scrollIntoView, opt-inawait map.clickAt({ lng: 34.78, lat: 32.08 });await map.wheelAt({ lng: 34.8, lat: 32.1 }, -600);// zooms around the pointerRuns as written. Every runnable example in these guides and the recipes is type-checked and runs in geowright's own test suite. The guides' examples run against its demo app: that is where their layer names, ids and coordinates come from.
In this guide
- QueriesFind features by layer, id, properties, location, layer type or source; strict and lazy like a Locator.
- Visible by defaultQueries match only what a user can see: the style's paint is evaluated for each feature.
- What an action waits forThe checks every action passes before real input is sent, and again when the press arrives.
- Failure messagesA failure lists what was on the map, why it did not match, and attaches an annotated screenshot.
- Touch and keyboardTap, pinch, rotate, one-finger pan, double tap and keyboard input on the map.
- Markers and popupsDOM markers and popups as normal Playwright Locators, and popups anchored on a feature.
- Geometry and drawingCompare a feature's full geometry, and draw with terra-draw or mapbox-gl-draw through real input.