elm-explorations / test

Write unit and fuzz tests for Elm code.
https://package.elm-lang.org/packages/elm-explorations/test/latest
BSD 3-Clause "New" or "Revised" License
236 stars 40 forks source link

Query.find returns different results based on selector order #185

Open mandla-noredink opened 2 years ago

mandla-noredink commented 2 years ago

Query.find seems to apply sets of selectors sequentially.

The first selector produces a set of results, on which the second selector runs, etc.

So for the example <div><div><div><div class="test"></div></div></div></div>:

1) Query.find [ tag "div", class "test" ] will return 4 matches, all of which will be <div class="test">

(one for each containing div and the matching div itself)

2) Query.find [ class "test", tag "div" ] will return 1 match, <div class="test">

This functionality is essentially chaining multiple Query.find calls in a row rather than as a single operation.

The documentation of the function does not suggest this behaviour, and gives the impression of an and-like functionality:

Find exactly one descendant element which matches all the given selectors. If no descendants match, or if more than one matches, the test will fail.

The code responsible can be found here:

https://github.com/elm-explorations/test/blob/1.2.2/src/Test/Html/Selector/Internal.elm