elm-explorations / elm-explorations/test

findAll with multiple selectors returns unexpected results

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

Description

Based on the documentation I was expecting that selectors passed to `findAll ` would be applied to the same element:

> Find the descendant elements which match all the given selectors.

This is not what I'm observing. It seems that selectors are applied one by one also to child nodes.

Example:

```




```

with selector ` findAll [Selector.class "c1", Selector.class "c2"]`

I'd expect this not to match anything, but it does match one element.

I hit this issue when writing code to find a div with a certain class. The query looked like `findAll [Selector.tag "div", Selector.class "c"]` for HTML structure:

```






```
I was very surprised to get multiple finds from `findAll `.

Code to illustrate the issue:

```
module ExampleTest exposing(exampleTest1,exampleTest2)

import Html exposing (div,a, p)
import Html.Attributes as Html
import Test.Html.Query exposing (fromHtml,findAll,count)
import Test.Html.Selector as Selector
import Test exposing (Test,test)
import Expect

exampleTest1 : Test
exampleTest1 = test "ExampleTest1 (expected 0)" <| \_ -> (div [] [ p [Html.class "c1"] [a [Html.class "c2"] []]])
|> fromHtml
|> findAll [Selector.class "c1", Selector.class "c2"]
|> count (Expect.equal <| 0)

exampleTest2 : Test
exampleTest2 = test "ExampleTest2 (expected 1)" <| \_ -> (div [] [ div [] [div [Html.class "c"] []]])
|> fromHtml
|> findAll [Selector.tag "div", Selector.class "c"]
|> count (Expect.equal <| 1)

```

```
>
> Compiling > Starting tests
>
> elm-test 0.19.1-revision12
> --------------------------
>
> Running 2 tests. To reproduce these results, run: elm-test --fuzz 100 --seed 370349610011760
>
> > ExampleTest
> > ExampleTest1 (expected 0)
>
> ▼ Query.fromHtml
>
>


>


>

>

>


>

>
>
> ▼ Query.findAll [ class "c1", class "c2" ]
>
> 1)
>

>
>
> ▼ Query.count
>
> Expect.equal
>
>
> > ExampleTest
> > ExampleTest2 (expected 1)
>
> ▼ Query.fromHtml
>
>

>

>

>

>

>

>
>
> ▼ Query.findAll [ tag "div", class "c" ]
>
> 1)

>

>
> 2)

>

>
>
> ▼ Query.count
>
> Expect.equal
>
>
>
> TEST RUN FAILED
>
> Duration: 281 ms
> Passed: 0
> Failed: 2
```

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.