elm-html-test
elm-html-test copied to clipboard
Regex matching for text
I found myself in the situation where I'd like to be able to match against part of a string within a text field.
For example:
https://github.com/terezka/line-charts/pull/38/files#diff-c75cfaadb0c1fe89dc19f42360af0317R91
In this case, the "10" part of the UI doesn't actually matter: what does matter is the "Age"
Makes sense to me! I'm familiar with this use case from Capybara tests.
What about this for an API?
textMatching : (String -> Bool) -> Selector
textContaining : String -> Selector
The former is maximally flexible - you could use regex, or a helper function, or Parser
, or anything else.
The latter would be the most common application of that function. (So you wouldn't have to say textMatching (Sting.contains "Age")
all the time.)
I just realized that my proposed textContaining
is actually how text
currently works.
This means it's not currently possible to search for (for example) an empty text node, e.g. text ""
doesn't do anything useful.
This seems like a useful distinction to make!