elm-html-test icon indicating copy to clipboard operation
elm-html-test copied to clipboard

Expect.Html?

Open rtfeldman opened this issue 7 years ago • 1 comments

Now that we've used this library quite a bit, I think I made a mistake putting functions returning an Expectation in the Query module. I think they should go in an Expect.Html module instead, meaning you could write code like this:

Before

import Html exposing (div, ul, li)
import Html.Attributes exposing (class)
import Test.Html.Query as Query
import Test exposing (test)
import Test.Html.Selector exposing (tag, classes)


test "The list has both the classes 'items' and 'active'" <|
    \() ->
        div []
            [ ul [ class "items active" ]
                [ li [] [ text "first item" ]
                , li [] [ text "second item" ]
                , li [] [ text "third item" ]
                ]
            ]
            |> Query.fromHtml
            |> Query.findAll [ tag "ul" ]
            |> Query.each
                [ Query.has [ tag "ul" ]
                , Query.has [ classes [ "items", "active" ] ]
                ]

After

The first line and last 3 lines are different.

import Expect.Html
import Html exposing (div, ul, li)
import Html.Attributes exposing (class)
import Test.Html.Query as Query
import Test exposing (test)
import Test.Html.Selector exposing (tag, classes)


test "The list has both the classes 'items' and 'active'" <|
    \() ->
        div []
            [ ul [ class "items active" ]
                [ li [] [ text "first item" ]
                , li [] [ text "second item" ]
                , li [] [ text "third item" ]
                ]
            ]
            |> Query.fromHtml
            |> Query.findAll [ tag "ul" ]
            |> Expect.Html.each
                [ Expect.Html.has [ tag "ul" ]
                , Expect.Html.has [ classes [ "items", "active" ] ]
                ]

This way, elm-htm-test pipelines would terminate with a call to an Expect. function the same way that other elm-test tests do.

This would be a breaking API change, of course, but now seems like a good time for one because https://github.com/eeue56/elm-html-test/pull/46 should be released as part of a MAJOR version bump anyway.

rtfeldman avatar Feb 03 '18 19:02 rtfeldman

I think this would be a great improvement and would help clarifying the api

stoeffel avatar Mar 07 '18 20:03 stoeffel