elm-explorations / elm-explorations/test

Query for and/or assert that an element has a named Attribute regardless of its value

Open
#95 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Elm
Stars
244
Forks
40
Avg merge
1d 23h
Merged PRs (30d)
2

Description

I would like to write a test that finds all the `button` elements within my view and asserts that they all have an `id` attribute. (I might also want to write a test that asserts that all the id values are unique, but I'm less concerned about that.) From what I can see, this isn't possible with the current code in the `Test.Html.Query` and `Test.Html.Selector` modules. In order to assert that an element has an `id`, I have to also give it the id's value.

I think I would like the attribute value to be a custom type with one option being `Any` so that if you called `Test.Html.Selector.id Any` you would get a `Selector` that matches on any element that contains an `id` attribute regardless of its value.

A new function `idAny` that takes no parameter might allow the existing `id` function to remain unchanged. I'm not sure which way would work better.

I would then be able to write a test like this:

```
test "Every button has an id" <|
\() ->
div []
[ button [ id "button_1" ] [ text "Button 1" ]
, button [ id "button_2" ] [ text "Button 2" ]
]
|> Query.fromHtml
|> Query.findAll [ tag "button" ]
|> Query.each
( Query.has [ id Any ] ) -- or ( Query.has [ idAny ] )
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.