View Source Adh
A tiny library of helpers to make assertions on DOM.
Powered by Floki.
installation
Installation
Add Adh to your mix.exs:
defp deps do
[
{:adh, "~> 0.1.0"}
]
end
usage
Usage
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 elementsdom_present: "ul"A ul is present in the documentdom_absent: "p"A p is absent from the documentdom_single: "ul"There's only one uldom_multi: "li"There are multiple lidom_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:
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`."}]