# Adh
[](https://github.com/carlotm/adh/actions/workflows/elixir.yml)
A tiny library of helpers to make assertions on DOM.
Powered by [Floki](https://hexdocs.pm/floki/Floki.html).
## Installation
Add Adh to your `mix.exs`:
```elixir
defp deps do
[
{:adh, "~> 0.1.0"}
]
end
```
## Usage
```elixir
Adh.dom_assert(html_string, assertions)
```
Where `assertions` is a Keyword list.
The currently available assertions are:
* `dom_count: {"li", 3}` There must be 3 li elements
* `dom_present: "ul"` A ul is present in the document
* `dom_absent: "p"` A p is absent from the document
* `dom_single: "ul"` There's only one ul
* `dom_multi: "li"` There are multiple li
* `dom_text: {"li:last-child", "o/"}` The text of the element is "o/"
* `dom_text: {"li", ["t1", "t2", "t3"]}` There are 3 li elements and their text is "ti", "t2" and "t3"
`Ahd.dom_assert` return a list of `:ok` if the assertion was succesfull, or `{:fail, reason}` otherwhise.
Example:
```elixir
iex(1)> html = "<p>o/ <span class='red'>dog</span></p>"
iex(2)> assertions = [dom_count: {"p", 1}, dom_text: {".red", "dig"}]
iex(2)> Adh.dom_assert(html, assertions)
[:ok, {:fail, "dom text: got `dog` instead of `dig`."}]
```