I’m happy to announce the release of elm-program-test 3.0.0, which has been a long time in the making. New in this version is the ability to test programs that make HTTP requests and use ports, along with many other improvements.
There is also a new documentation site with guidebooks showing how to test programs with interactive views, test programs with Cmds, and test programs with ports.
And finally, there is a guide for upgrading from elm-program-test 2.x to 3.x for those who have already been using the package.
If you haven’t heard of elm-program-test before, it is designed to provides a convenient API that works with elm-test (including Test.Html
) to test your Elm programs as complete units. Testing your programs at this level provides test coverage that is resilient even to drastic refactorings of your application architecture, and encourages tests that make it clear how end-users and external services will interact with your program.
Here’s a brief example of such a test (for more details about how to get started, see the new guidebooks.
test "successful registration" <|
\() ->
start
|> fillIn "name" "Name" "Bailey Sheppard"
|> fillIn "street-address" "Street Address" "14 North Moore Street"
|> fillIn "postcode" "Postal Code" "12345"
|> clickButton "Register"
|> ensureViewHas [ text "Loading..." ]
|> simulateHttpOk "POST"
"https://example.com/api/v1/voter-registration"
"""{"status":1}"""
|> Expect.all
[ expectViewHasNot [ text "Loading..." ]
, expectViewHas [ text "Registration successful!" ]
]
start =
ProgramTest.createDocument
{ init = Main.init
, update = Main.update
, view = Main.view
}
|> ProgramTest.start ()
Thanks to @brookeangel for help with some of the new features, and to @mthadley and @glitteringkatie for code and documentation reviews.