# `Combo.Inertia.Testing`
[🔗](https://github.com/combo-lab/combo_inertia/blob/v2.0.0/lib/combo/inertia/testing.ex#L1)

Helpers for testing Inertia responses.

# `inertia_component`

```elixir
@spec inertia_component(Plug.Conn.t()) :: String.t() | nil
```

Gets the Inertia component for given `%Plug.Conn{}`.

## Example

    use MyApp.Web.ConnCase
    import Combo.Inertia.Testing

    describe "GET /" do
      test "renders the home page", %{conn: conn} do
        conn = get("/")
        assert inertia_component(conn) == "Home"
      end
    end

# `inertia_errors`

```elixir
@spec inertia_errors(Plug.Conn.t()) :: map()
```

Gets the Inertia errors for given `%Plug.Conn{}`.

If there are errors available in the current page props, they will be returned.
Otherwise, errors that have been stored in the session will be retrieved.

## Example

    use MyApp.Web.ConnCase
    import Combo.Inertia.Testing

    describe "POST /users" do
      test "fails when name empty", %{conn: conn} do
        conn = post("/users", %{"name" => ""})

        assert %{user: %{id: 1}} = inertia_props(conn)
        assert redirected_to(conn) == "/users"
        assert inertia_errors(conn) == %{"name" => "can't be blank"}
      end
    end

# `inertia_props`

```elixir
@spec inertia_props(Plug.Conn.t()) :: map() | nil
```

Gets the Inertia props for given `%Plug.Conn{}`.

## Example

    use MyApp.Web.ConnCase
    import Combo.Inertia.Testing

    describe "GET /" do
      test "renders the home page", %{conn: conn} do
        conn = get("/")
        assert %{user: %{id: 1}} = inertia_props(conn)
      end
    end

---

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