BurntCaramel
Ensemble - Test LiveView with ARIA Roles
I made ensemble for testing ARIA roles in Phoenix LiveView. If you’ve ever used react-testing-library or Playwright you might have come across getByRole , it’s gold for both making writing tests simpler and improving the accessibility of your web app.
import Ensemble and you have access to has_role?/3 and role/3, which are like has_element?/3 and element/3 from LiveViewTest but accept ARIA roles and an accessible name instead of a selector:
defmodule TodoLiveTest do
use YourAppWeb.ConnCase, async: true
import Phoenix.LiveViewTest
import Ensemble
test "has landmarks and nav", %{conn: conn} do
{:ok, view, _html} = live(conn, "/todos")
assert view |> role(:banner) |> render() =~ ~r|^<header|
assert view |> role(:main) |> render() =~ ~r|^<main|
assert view |> role(:contentinfo) |> render() =~ ~r|^<footer|
assert view |> role(:navigation, "Primary") =~ ~r|^<nav|
assert view |> role(:link, "Home") =~ ~r|^<a href="/"|
end
test "subscribe form", %{conn: conn} do
assert view |> role(:form) =~ ~r|^<form|
assert view |> role(:textbox, "Email") =~ ~r|^<input type="text"|
assert view |> role(:checkbox, "Send newsletter") =~ ~r|^<input type="checkbox"|
assert view |> role(:button, "Subscribe") =~ ~r|^<button type="submit"|
end
test "submit form", %{conn: conn} do
assert view
|> role(:button, "Subscribe")
|> render_click() =~ "Thanks for subscribing!"
end
end
Most Liked
wceolin
As someone coming from a JS background, one of things I was missing was something like the react-testing-library. I was actually thinking about creating a library for this, so thank you so much for creating it!
I’m gonna give it a try.
1
Popular in Libraries
It is a well-know topic within the Elixir community: “To mock or not to mock? :)”
Every alchemist probably has his / her own opinion con...
New
Only 650 LOC, wrote for fun :slight_smile:
New
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New
LiveMotion enables high performance animations declared on the server and run on the client.
As a follow up to my previous thread A libr...
New
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
PhoenixWS - Websockets over Phoenix Channels
Source code on Github here: https://github.com/tmbb/phoenix_ws
Phoenix channels are a great...
New
Hi everyone!
I’m thrilled to announce a huge thing. We have been developing Elixir Moon Design System for quite a while. We are finally ...
New
Expat is a tiny experiment I did for extracting patterns and being able to reuse them (compose and share patterns between elixir librarie...
New
Grizzly is a library for working with Z-Wave devices. Z-Wave is a low-frequency radio protocol for controlling smart home devices on a me...
New
Hello!
Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
New
Other popular topics
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New







