Skip to content

waygraph / urlMatches

Function: urlMatches() ​

urlMatches(pattern): Trait

Defined in: src/engine/trait/trait.ts:89

Passes once the page's URL matches pattern, waiting for real navigation. pattern is a structured URLPatternInit (the same shape the standard URLPattern Web API takes) - { pathname, hostname, search, hash, ... } - not a hand-written regex. Whichever components you don't specify default to "match anything" there, so a hybrid SPA tacking its own ?tab=cart&session=xyz onto the URL never breaks a pathname-only check - there's no separate flag for that, omission already means "don't care." Reach for a bespoke Trait with a raw regex only if a route genuinely needs pattern power URLPatternInit's fields can't express.

Parameters ​

pattern ​

URLPatternInit

Returns ​

Trait

Examples ​

ts
Trait.url({ pathname: "/inventory.html" })
ts
Trait.url({ hostname: "checkout.example.com", pathname: "/pay" })
ts
Trait.url({ pathname: "/users/:id" })   // named path params, matched structurally

waygraph 0.18.3 (alpha) · Node 24+ · peer @playwright/test ^1.40.0 · syntax may change before 1.0: see what was removed