# `Plushie.Test`
[🔗](https://github.com/plushie-ui/plushie-elixir/blob/v0.7.2/lib/plushie/test.ex#L1)

Test helpers for Plushie applications.

## Setup

Call `Plushie.Test.setup!()` in your `test/test_helper.exs` before
`ExUnit.start()`:

    # test/test_helper.exs
    Plushie.Test.setup!()
    ExUnit.start()

This starts the shared renderer session pool and configures ExUnit
to exclude tests tagged for backends not currently active.

### Backend selection

Set `PLUSHIE_TEST_BACKEND` to choose the backend:

    mix test                                    # mock (default)
    PLUSHIE_TEST_BACKEND=headless mix test       # headless rendering
    PLUSHIE_TEST_BACKEND=windowed mix test       # real windows

### Backend-specific tests

Tag tests with the **minimum backend** they require:

    @tag backend: :headless   # runs in headless + windowed, skipped in mock
    test "renders correctly" do ... end

    @tag backend: :windowed   # runs only in windowed
    test "screenshot matches" do ... end

Backend capability is hierarchical: mock < headless < windowed.
Tag with the lowest backend that provides what the test needs.
Untagged tests run in all modes.

## Tree snapshot testing

    test "initial view snapshot" do
      model = MyApp.init([])
      tree = MyApp.view(model)
      Plushie.Test.assert_tree_snapshot(tree, "test/snapshots/initial_view.json")
    end

On first run, `assert_tree_snapshot/2` writes the snapshot file. On subsequent
runs, it compares against the stored snapshot. Update snapshots with:

    PLUSHIE_UPDATE_SNAPSHOTS=1 mix test

# `assert_tree_snapshot`

```elixir
@spec assert_tree_snapshot(tree :: map(), path :: String.t()) :: :ok
```

Asserts that `tree` matches the stored structural snapshot at `path`.

On first run (file does not exist), writes the snapshot.
On subsequent runs, compares and fails with a diff if different.
Set `PLUSHIE_UPDATE_SNAPSHOTS=1` to overwrite existing snapshots.

# `setup!`

```elixir
@spec setup!(opts :: keyword()) :: keyword()
```

Sets up the Plushie test infrastructure.

Call this from your `test/test_helper.exs` before `ExUnit.start()`.
Starts the shared renderer session pool and configures backend-based
test exclusions.

Returns the ExUnit exclusion options. Pass them to `ExUnit.start/1`:

    # test/test_helper.exs
    plushie_opts = Plushie.Test.setup!()
    ExUnit.start(plushie_opts)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
