eeue56 / elm-html-test

Test elm-html in Elm!
http://package.elm-lang.org/packages/eeue56/elm-html-test/latest
BSD 3-Clause "New" or "Revised" License
67 stars 15 forks source link

Query.find: the order of Selectors matters #68

Open WToma opened 6 years ago

WToma commented 6 years ago

I have a table with some CSS class. I use the same CSS class name to denote the tr and td elements in the table. When using Query.find to find my table, this works: Query.find [ class "myClassName", tag "table" ], and this doesn't because it'll find all children with that class: Query.find [ tag "table", class "myClassName" ].

This is either a bug, or missing documentation. Based on the documentation for find I expect that the selectors are in an AND relationship, thus the order should not matter.

Full example (you can see that one of the tests passes and the other fails):

Example.elm

module Example exposing (..)

import Test exposing (Test, describe, test)
import Test.Html.Query as Query
import Test.Html.Selector as Selector exposing (tag, class)
import Html exposing (Html, div, table, tr)
import Html.Attributes as Attributes

suite : Test
suite =
    describe "This unexpected behavior in Test.Html.Query"
        [ test "selecting the tag and class one way" <|
            \() ->
                tableWithClassName
                    |> Query.fromHtml
                    |> Query.find [ class "myClassName", tag "table" ]
                    |> Query.has [ tag "table" ]
        , test "selecting the tag and class the other way" <|
            \() ->
                tableWithClassName
                    |> Query.fromHtml
                    |> Query.find [ tag "table", class "myClassName" ]
                    |> Query.has [ tag "table" ]
        ]

tableWithClassName : Html msg
tableWithClassName =
    div []
        [ table
            [ Attributes.class "myClassName" ]
            [ tr [ Attributes.class "myClassName" ] [] ]
        ]

elm-package.json:

{
    "version": "1.0.0",
    "summary": "Test Suites",
    "repository": "https://github.com/user/project.git",
    "license": "BSD3",
    "source-directories": [
        "..",
        "."
    ],
    "exposed-modules": [],
    "dependencies": {
        "eeue56/elm-html-test": "5.2.0 <= v < 6.0.0",
        "elm-community/elm-test": "4.0.0 <= v < 5.0.0",
        "elm-lang/core": "5.1.1 <= v < 6.0.0",
        "elm-lang/html": "2.0.0 <= v < 3.0.0"
    },
    "elm-version": "0.18.0 <= v < 0.19.0"
}