# Assertions and Waiting (Humand E2E)

Prefer web-first assertions and Playwright auto-waiting. Avoid manual sleeps.

## Core principles

- Assert behavior visible to users.
- Use `expect(...).toBeVisible()` / `toHaveURL()` / `toHaveCount()` over custom polling.
- Keep repeated assertion logic in page object `expect*` helpers.

## Recommended patterns

```ts
await expect(page).toHaveURL(/\/goals\/cycles\/\d+\/edit/);
await expect(goalsCyclesPage.newCycleButton).toBeEnabled();
await expect(page.getByRole('alert')).toContainText(/guardado|exitoso/i);
```

## Waiting rules

- Prefer locator-driven waits (`expect(locator)...`) instead of explicit `waitForTimeout`.
- `waitForTimeout` is allowed only for short UI debounce situations (<= 500ms).
- For navigation transitions, prefer `waitForURL`.
- For page stabilization, use page-level helper methods (for example `waitForPageLoad()`).

## Assertion placement

- Tests keep scenario-level assertions.
- Page objects can include reusable `expect*` helpers for common page-state checks.
- Do not hide business assertions deeply inside generic helpers.

## Anti-patterns

- `await page.waitForTimeout(5000)` as a generic fix
- asserting implementation details (CSS class names, internals)
- weak assertions like only checking "page did not crash"
