How to test and assert order of elements in LiveView?

So I don’t know why I never thought of this before but out of the box you can use CSS selectors along with has_element?/3 for much more fine-grained and reliable results than my current regex solution:

assert has_element?(lv, ".my-list li:nth-child(1)", "One")
assert has_element?(lv, ".my-list li:nth-child(2)", "Two")
assert has_element?(lv, ".my-list li:nth-child(3)", "Three")

cc: @travisf

3 Likes