avh4 / elm-program-test / SimulatedEffect.Http

This module parallels elm/http's Http module. Pull requests are welcome to add any functions that are missing.

The functions here produce SimulatedEffects instead of Cmds, which are meant to be used to help you implement the function to provide when using ProgramTest.withSimulatedEffects.

Requests

get : { url : String, expect : Expect msg } -> ProgramTest.SimulatedEffect msg

Create a GET request.

post : { url : String, body : Body, expect : Expect msg } -> ProgramTest.SimulatedEffect msg

Create a POST request.

request : { method : String, headers : List Header, url : String, body : Body, expect : Expect msg, timeout : Maybe Basics.Float, tracker : Maybe String } -> ProgramTest.SimulatedEffect msg

Create a custom request.

Header


type alias Header =
( String, String )

An HTTP header for configuring requests.

header : String -> String -> Header

Create a Header.

Body


type Body

Represents the body of a Request.

emptyBody : Body

Create an empty body for your Request.

stringBody : String -> String -> Body

Put some string in the body of your Request.

jsonBody : Json.Encode.Value -> Body

Put some JSON value in the body of your Request. This will automatically add the Content-Type: application/json header.

Expect


type Expect msg

Logic for interpreting a response body.

expectString : (Result Http.Error String -> msg) -> Expect msg

Expect the response body to be a String.

expectJson : (Result Http.Error a -> msg) -> Json.Decode.Decoder a -> Expect msg

Expect the response body to be JSON.

expectWhatever : (Result Error () -> msg) -> Expect msg

Expect the response body to be whatever.


type alias Error =
Http.Error

Elaborate Expectations

expectStringResponse : (Result x a -> msg) -> (Response String -> Result x a) -> Expect msg

Expect a Response with a String body.


type alias Response body =
Http.Response body

Tasks

task : { method : String, headers : List Header, url : String, body : Body, resolver : Resolver x a, timeout : Maybe Basics.Float } -> ProgramTest.SimulatedTask x a

Just like request, but it creates a Task.


type Resolver x a

Describes how to resolve an HTTP task.

stringResolver : (Response String -> Result x a) -> Resolver x a

Turn a response with a String body into a result.