brian-watkins/elm-spec/1.0.1

NOTE: the latest version is 3.3.2

Spec.Markup

Target, observe and make claims about aspects of an HTML document.

Target an HTML Element

target : ( Selector a, Context model ) -> Command msg

A step that identifies an element to which later steps will be applied.

Spec.when "the button is clicked twice"
  [ Spec.Markup.target << by [ tag "button" ]
  , Spec.Markup.Event.click
  , Spec.Markup.Event.click
  ]

Observe an HTML Document

Represents an observation of HTML.

Observe all HTML elements that match the selector provided to Spec.Markup.query.

Spec.Markup.observeElements
  |> Spec.Markup.query << by [ attribute ("data-attr", "some-value") ]
  |> Spec.expect (Spec.Claim.isListWithLength 3)

If no elements match the query, then the subject of the claim will be an empty list.

Observe an HTML element that matches the selector provided to Spec.Markup.query.

Spec.Markup.observeElement
  |> Spec.Markup.query << by [ attribute ("data-attr", "some-value") ]
  |> Spec.expect (Spec.Markup.hasText "something fun")

If the element cannot be found in the document, the claim will be rejected.

Observe an HTML element that may not be present in the document.

Use this observer if you want to make a claim about the presence or absence of an HTML element.

Spec.Markup.observe
  |> Spec.Markup.query << by [ id "some-element" ]
  |> Spec.expect Spec.Claim.isNothing
query : ( Selector Element, MarkupObservation a ) -> Observer model a

Search for HTML elements.

Use this function in conjunction with observe, observeElement, or observeElements to observe the HTML document.

observeTitle : Observer model String

Observe the title of an HTML document.

Note: It only makes sense to observe the title if your program is constructed with Browser.document or Browser.application.

Make Claims about an HTML Element

Represents an HTML element.

hasText : String -> HtmlElement -> Verdict

Claim that the text belonging to the HTML element contains the given text.

Note that the text belonging to an observed HTML element includes the text belonging to all its descendants.

hasAttribute : ( String, String ) -> HtmlElement -> Verdict

Claim that the HTML element has the given attribute with the given value.

Spec.Markup.observeElement
  |> Spec.Markup.query << by [ tag "div" ]
  |> Spec.expect (
    Spec.Markup.hasAttribute ("class", "red")
  )