Skip to content
// EFFECT DAYS 2026

Locator unstable

Locators over a minimal structural tree, so one locator works on a story's view value and on TestHost's rendered tree alike.

A node is anything with some of tag, attrs, text and children: an element has a tag, a text node has text. Locators match elements. text matches the innermost elements whose text contains the string, attr and className match by attribute, testId by a web data-testid or a React Native testID, and inside narrows a locator to the subtree of another. and and not combine locators, so li.row:not(.selected) button is inside(and(tag("li"), className("row"), not(className("selected"))), tag("button")). Locators are pipeable, and inside and and have pipe forms.

Example Finding a row's button

import { Locator } from "effect/ui/testing"
const row = (id: string) => ({
tag: "li",
attrs: { "data-testid": id },
children: [{ tag: "button", children: [{ text: "Save" }] }]
})
const tree = { tag: "ul", children: [row("row-1"), row("row-2")] }
const button = Locator.get(tree, Locator.inside(Locator.testId("row-2"), Locator.text("Save")))
console.log(button === tree.children[1].children[0]) // true
const piped = Locator.text("Save").pipe(Locator.inside(Locator.testId("row-2")))
console.log(Locator.get(tree, piped) === button) // true
18 exports Since v4.2.0 Source

Combinators

and

unstable
Since v4.2.0

Elements every locator finds. self.pipe(Locator.and(that)) is Locator.and(self, that).

Signature

declare const and: {
(that: Locator): (self: Locator) => Locator;
(self: Locator, that: Locator, ...rest: readonly Array<Locator>): Locator;
}

not

unstable
Since v4.2.0

Elements under the root, the root included, that locator doesn't find.

Details

not(text("Save")) also finds the ancestors of the innermost match, since text finds only that one.

Signature

declare function not(locator: Locator): Locator

Constructors

make

unstable
Since v4.2.0

A locator from its description and the function that finds its elements under a root, in document order.

Signature

declare function make(description: string, all: <N extends Node>(root: N) => readonly Array<N>): Locator

Events

fire

unstable
Since v4.2.0

Sends event with payload to node. The innermost element with a handler for it, node or an ancestor, gets it.

Details

Payloads are plain data shaped by the vocabulary, such as { value } for input. A scene's view value has no host, so scene tests use the fire and click steps of Scene.Steps instead.

Signature

declare function fire(node: Firable, event: string, payload: unknown): void

Getters

elements

unstable
Since v4.2.0

Every element under root, root included, in document order.

Signature

declare function elements<N extends Node>(root: N): readonly Array<N>

textOf

unstable
Since v4.2.0

The text of a node and everything under it.

Signature

declare function textOf(node: Node): string

Locators

attr

unstable
Since v4.2.0

Elements with the attribute name, equal to or matching value when one is given.

Details

A string matches the whole value, so attr("class", "row") skips class="row selected"; use className for that. A prefix is /^prefix/.

Signature

declare function attr(name: string, value?: string | RegExp): Locator

className

unstable
Since v4.2.0

Elements whose class has the token name, split on ASCII whitespace as in CSS.

Signature

declare function className(name: string): Locator

inside

unstable
Since v4.2.0

Matches of locator that are descendants of elements matched by container. The container comes first in both forms: button.pipe(Locator.inside(form)) is Locator.inside(form, button).

Signature

declare const inside: {
(container: Locator): (locator: Locator) => Locator;
(container: Locator, locator: Locator): Locator;
}

tag

unstable
Since v4.2.0

Elements with the tag tag.

Signature

declare function tag(tag: string): Locator

testId

unstable
Since v4.2.0

Elements whose data-testid attribute, or React Native testID prop, equals id.

Signature

declare function testId(id: string): Locator

text

unstable
Since v4.2.0

The innermost elements whose text contains text, or equals it with { exact: true }.

Signature

declare function text(text: string, options?: {
readonly exact?: boolean;
}): Locator

Models

Firable

interface unstable
Since v4.2.0

A node that can receive events, as TestHost's nodes can.

Signature

interface Firable extends Node {
readonly fire: (event: string, payload: unknown) => void;
}

Locator

interface unstable
Since v4.2.0

Finds elements under a root, in document order.

Signature

interface Locator extends Pipeable {
readonly all: <N extends Node>(root: N) => readonly Array<N>;
readonly description: string;
}

Node

interface unstable
Since v4.2.0

The structural tree every locator runs over.

Details

props holds the typed values set with .prop, such as a field's value and checked, which aren't attributes. A scene's view value and a TestHost tree both have them, and a vocabulary's readers, such as HtmlLocator.value, read them.

Signature

interface Node {
readonly attrs?: Readonly<Record<string, string | undefined>>;
readonly children?: readonly Array<Node>;
readonly props?: Readonly<Record<string, unknown>>;
readonly tag?: string;
readonly text?: string;
}

Queries

all

unstable
Since v4.2.0

Every match, in document order.

Signature

declare function all<N extends Node>(root: N, locator: Locator): readonly Array<N>

get

unstable
Since v4.2.0

The one match. Throws when there's none or several.

Signature

declare function get<N extends Node>(root: N, locator: Locator): N

query

unstable
Since v4.2.0

The one match, or undefined. Throws when there are several.

Signature

declare function query<N extends Node>(root: N, locator: Locator): N | undefined