Monocle - Liveview Test the presence of elements in a rendered component

This library was created to test the presence of elements in a rendered component using their data-test attributes, data-test attribute values or a combination of both. This library relies on the parsing abilities of Floki.

For example, if we wanted to test the existence of this button in a rendered page

<div data-test-confirmation-button>Confirm</div>

We can use the following

assert we_see_attribute(html, "confirmation button", content: "Confirm")

We can also expect a certain amount of elements by using

assert we_see_exactly(html, 2, attribute: ""confirmation button", content: "Confirm")

This is great for testing conditional components and conditionally rendered elements on a page.

For more info, you can read the docs
https://hexdocs.pm/monocle/Monocle.html

5 Likes