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
237 stars 39 forks source link

Query.has and Query.hasNot seem to query children as well #74

Open austinshenk opened 5 years ago

austinshenk commented 5 years ago

I'm running into an issue where the following test case is failing when, based on the documentation for the has and hasNot functions, it should be passing. The following is the test case itself and after is the relevant console log.

table
  |> Query.fromHtml
  |> Query.find [ Selector.tag "thead" ]
  |> Query.find [ Selector.tag "tr" ]
  |> Query.hasNot [ Selector.attribute (Aria.colIndex 1) ]
> Table
> colindex on tr
> is not added for a non contiguous heading list

    ▼ Query.fromHtml

        <table aria-colcount="5" aria-rowcount="1">
            <thead>
                <tr>
                    <th aria-colindex="1">
                        label
                    </th>
                    <th aria-colindex="3">
                        label
                    </th>

                    <th aria-colindex="5">
                        label
                    </th>
                </tr>
            </thead>
            <tbody>
                <tr aria-rowindex="2">
                </tr>
            </tbody>
        </table>

    ▼ Query.find [ tag "thead" ]

        1)  <thead>
                <tr>
                    <th aria-colindex="1">
                        label
                    </th>
                    <th aria-colindex="3">
                        label
                    </th>
                    <th aria-colindex="5">
                        label
                    </th>
                </tr>
            </thead>

    ▼ Query.find [ tag "tr" ]

        1)  <tr>
                <th aria-colindex="1">
                    label
                </th>
                <th aria-colindex="3">
                    label
                </th>
                <th aria-colindex="5">
                    label
                </th>
            </tr>

    ▼ Query.hasNot [ attribute "aria-colindex" "1" ]

    > has not attribute "aria-colindex" "1"

My thought is that this would pass because the tr tag does not have a aria-colindex attribute. This is a similar case shown in the documentation for the package, but is not executing as expected. After playing with it a bit I figure out that it was due to the fact that there was a child th element that did have a aria-colindex="1" which makes the test fail. The only way I've been able to get around this issue is to modify the table's structure to not include the child th tags, but this is not ideal.

I'm kind of asking 2 questions here which is

  1. Is this functionality expected?
  2. If it is, than how would you recommend testing for an attribute to not be on an element?
mgold commented 5 years ago

This is not expected and I've opened a PR with a failing test. Thanks for the bug report!