Functions for the initial setup of a scenario.
Internal.Setup model msg
Represents the initial state of the world for a scenario.
initForApplication : (Url -> Browser.Navigation.Key -> ( model, Platform.Cmd.Cmd msg )) -> Setup model msg
Use the init function for a program created with Browser.application
to set the
initial state for the scenario. You could do something like:
Spec.given (
Spec.Setup.initForApplication (App.init testFlags)
|> Spec.Setup.withDocument App.view
|> Spec.Setup.withUpdate App.update
)
If your scenario involves location changes, you'll want to use this function in
conjunction with Spec.Setup.forNavigation
to provide
those extra functions that an application requires. Providing these functions
is not necessary, but if you do not provde them, your spec will fail with an error
if it is setup with initForApplication
and it tries to make location changes.
You can also use Spec.Setup.withLocation
to set the URL that
will be passed to the application's init function at the start of the scenario.
So, a full setup for an application might look something like this:
Spec.given (
Spec.Setup.initForApplication (App.init testFlags)
|> Spec.Setup.withDocument App.view
|> Spec.Setup.withUpdate App.update
|> Spec.Setup.forNavigation
{ onUrlChange = App.urlDidChange
, onUrlRequest = App.urlChangeRequested
}
|> Spec.Setup.withLocation (someUrlWithPath "/sports")
)
init : ( model, Platform.Cmd.Cmd msg ) -> Setup model msg
Provide an initial program model and command. The command will be executed as the first step in the scenario script.
You might use init
in conjunction with the init
function of the program whose
behavior the scenario describes. In that case you could do something like:
Spec.given (
Spec.Setup.init (App.init testFlags)
|> Spec.Setup.withUpdate App.update
|> Spec.Setup.withView App.view
)
If you are describing the behavior of a program created with Browser.application
then
consider using initForApplication
instead.
initWithModel : model -> Setup model msg
Provide an initial model for the program whose behavior this scenario describes.
withLocation : Url -> Setup model msg -> Setup model msg
Set up the scenario to begin with a particular location.
If the program whose behavior is being described was created with Browser.application
then
this Url
will be provided to the init
function. In any case, this location will serve as
the base href, and any location changes will be relative to this location.
By default, the scenario begins with the location http://elm-spec/
withUpdate : (msg -> model -> ( model, Platform.Cmd.Cmd msg )) -> Setup model msg -> Setup model msg
Provide the update
function for the program whose behavior the scenario describes.
withView : (model -> Html msg) -> Setup model msg -> Setup model msg
Provide the view
function for the program whose behavior the scenario describes, where
this program is created with Browser.sandbox
or Browser.element
.
withDocument : (model -> Browser.Document msg) -> Setup model msg -> Setup model msg
Provide the view
function for the program whose behavior the scenario describes, where
this program is created with Browser.document
or Browser.application
.
withSubscriptions : (model -> Platform.Sub.Sub msg) -> Setup model msg -> Setup model msg
Provide the subscriptions
function for the program whose behavior the scenario describes.
forNavigation : { onUrlRequest : Browser.UrlRequest -> msg, onUrlChange : Url -> msg } -> Setup model msg -> Setup model msg
If the scenario is describing a program created with Browser.application
, you can use
this function to supply the program's onUrlRequest
and onUrlChange
functions.
Use this in conjunction with initForApplication
to describe a scenario that involves location changes.