Observe and make claims about how the Browser presents an HTML document: its title, its location, the viewport parameters, window visibility, and so on.
Represents the Browser's presentation of an HTML document.
observe : Spec.Observer.Observer model Navigator
Observe how a Browser presents an HTML document.
title : Spec.Claim.Claim String -> Spec.Claim.Claim Navigator
Claim that the title of the HTML document satisfies the given claim.
Spec.it "has the correct title" (
Spec.Navigator.observe
|> Spec.expect (
Spec.Navigator.title <|
Spec.Claim.isEqual Debug.toString
"My Cool App"
)
)
Note: It only makes sense to make a claim about the title if your program is
constructed with Browser.document
or Browser.application
.
{ x : Basics.Float, y : Basics.Float }
Represents the offset of a viewport.
viewportOffset : Spec.Claim.Claim ViewportOffset -> Spec.Claim.Claim Navigator
Claim that the browser's viewport offset satisfies the given claim.
Use this function to claim that the viewport of the browser window
has been set to a certain position via Browser.Dom.setViewport
.
Spec.it "has the correct scroll position" (
Spec.Navigator.observe
|> Spec.expect (
Spec.Navigator.viewportOffset <|
Spec.Claim.specifyThat .y <|
Spec.Claim.isEqual Debug.toString 27
)
)
Note: If you'd like to make a claim about the viewport offset of an element set via
Browser.Dom.setViewportOf
, use Spec.Markup.observeElement
and Spec.Markup.property to make a claim about its
scrollLeft
and scrollTop
properties.
location : Spec.Claim.Claim String -> Spec.Claim.Claim Navigator
Claim that the location of the document satisfies the given claim.
Spec.it "has the correct location" (
Spec.Navigator.observe
|> Spec.expect (
Spec.Navigator.location <|
Spec.Claim.isEqual Debug.toString
"http://fake-server.com/something-fun"
)
)
This is useful to observe that Browswer.Navigation.load
,
Browser.Navigation.pushUrl
, or Browser.Navigation.replaceUrl
was
executed with the value you expect.
Note that you can use Spec.Setup.withLocation to set the base location of the document at the start of the scenario.
expectReload : Spec.Expectation model
Expect that a Browser.Navigation.reload
or Browser.Navigation.reloadAndSkipCache
command was executed.
resize : ( Basics.Int, Basics.Int ) -> Spec.Step.Step model msg
A step that simulates resizing the browser window to the given (width, height).
This will trigger a resize
DOM event on the window object.
By default, elm-spec sets the browser window size to 1280 x 800.
Note that elm-spec fakes the browser window size. So if you are viewing elm-spec specs in a real browser, then you won't actually see the window size change, but the Elm program will think it has.
setViewportOffset : ViewportOffset -> Spec.Step.Step model msg
A step that changes the offset of the browser viewport.
Use this step to simulate a user scrolling the web page.
By default, elm-spec sets the browser viewport offset to { x = 0, y = 0 }
.
Note that elm-spec fakes the browser viewport offset. So if you are viewing elm-spec specs in a real browser, then you won't actually see the viewport offset change, but the Elm program will think it has.
hide : Spec.Step.Step model msg
A step that simulates hiding the window from view.
This will trigger a visibilitychange
DOM event on the document object.
Note that elm-spec fakes the browser window visibility. So if you are viewing elm-spec specs in a real browser, then you won't actually see the window visibility change, but the Elm program will think it has.
show : Spec.Step.Step model msg
A step that simulates the window returning into view.
This will trigger a visibilitychange
DOM event on the document object.
Note that elm-spec fakes the browser window visibility. So if you are viewing elm-spec specs in a real browser, then you won't actually see the window visibility change, but the Elm program will think it has.