Skip to content

Scene queries

Find display objects by their label property, decoupling tests from scene graph hierarchy.

Throws if the label is not found.

const { container } = mountScene(() => (
<Container label="scene">
<Sprite label="player" />
</Container>
));
const player = getByLabel(container, "player");
expect(player.x).toBe(100);

Same as getByLabel but returns undefined instead of throwing.

const maybe = queryByLabel(container, "missing-label"); // undefined

Find all display objects with the given label.

const enemies = getAllByLabel(container, "enemy");
expect(enemies).toHaveLength(3);