Skip to content

Matching for text equality or containing text #66

@bertdemiranda

Description

@bertdemiranda

According to the documentation of function Test.Html.Selector.text : String -> Selector

It "Matches elements that have a text attribute with the given value."
which suggests to me that a test for string equality would be performed.

Yet when I try the following test:

module HasTest exposing (..)

import Html
import Test.Html.Query as Query
import Test exposing (Test, test)
import Test.Html.Selector exposing (text)


hasTest : Test
hasTest =
    test "Button has the expected text" <|
        \() ->
            Html.button [] [ Html.text "????????I'm a button!????????" ]
                |> Query.fromHtml
                |> Query.has [ text "I'm a button!" ]

the test succeeds.

When I look at function Test.Html.Selector.Internal.query

(...)
Text text ->
    List.concatMap (fn (ElmHtml.Query.ContainsText text)) elems
(...)

then it calls indeed for a string containing match.

Also considering issue "Regex matching for text #58", should this behavior be corrected or should the documentation be changed/clarified?

Otherwise, how does one test for string equalitiy?
Is it possible to extract somehow the actual string from the query followed by a string equality check like so:

Html.button [] [ Html.text "????????I'm a button!????????" ]
    |> Query.fromHtml
    |> ...get string value(s)...
    |> Expect.equal "I'm a button!"

that should then fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions