avh4/elm-program-test/3.3.0

NOTE: the latest version is 4.0.1

Test.Http

Convenience functions for testing HTTP requests. Pull requests are welcome to add more useful functions.

Expectations

These functions provide some convenient checks that can be used with ProgramTest.expectHttpRequest.

Decoder requestBody
-> (requestBody -> Expectation)
-> HttpRequest x a
-> Expectation

A convenient way to check something about the request body of a pending HTTP request.

...
    |> ProgramTest.expectHttpRequest "POST"
        "https://example.com/ok"
        (Test.Http.expectJsonBody
            (Json.Decode.field "version" Json.Decode.string)
            (Expect.equal "3.1.5")
        )
hasHeader : String -> String -> HttpRequest x a -> Expectation

Assert that the given HTTP request has the specified header.

...
    |> ProgramTest.expectHttpRequest "POST"
        "https://example.com/ok"
        (Test.Http.hasHeader "Content-Type" "application/json")

Responses

These are ways to easily make Http.Response values for use with ProgramTest.simulateHttpResponse.

timeout : Response body

This is the same as Http.Timeout_, but is exposed here so that your test doesn't need to import both Http and Test.Http.

networkError : Response body

This is the same as Http.NetworkError_, but is exposed here so that your test doesn't need to import both Http and Test.Http.

{ statusCode : Int
, headers : List ( String, String )
, body : body
}
-> Response body

This is a more convenient way to create Http.BadStatus_ and Http.GoodStatus_ values.

Following the logic in elm/http, this will produce Http.GoodStatus_ if the given status code is in the 200 series, otherwise it will produce Http.BadStatus_.