eeue56 / eeue56/elm-html-test

Expect.Html?

Open
#48 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
Elm
Stars
68
Forks
15
PR merge metrics
No merged PRs in 30d

Description

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

```elm
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._

```elm
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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing the Query module and the API examples in this issue, then inspect pull request #46 for the related release context. Done means the expectation functions are exposed through Expect.Html, the documented pipelines use that API, and the breaking major-version change is accounted for.

Written by the indexing model from the issue text.

Assessment

Domain
testing
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.