Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/ProgramTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module ProgramTest exposing
, routeChange
, update
, expectModel
, withModel
, expectLastEffect, ensureLastEffect
, simulateLastEffect
, fail, createFailed
Expand Down Expand Up @@ -179,6 +180,7 @@ but you may find them useful to test things that are not yet directly supported

@docs update
@docs expectModel
@docs withModel


## Low-level functions for effects
Expand Down Expand Up @@ -1917,6 +1919,33 @@ expectModel assertion =
>> done


{-| A way to use the current model in your simulations.

When possible, you should not rely on your internal model but on the view to check that your program is behaving as expected.
This function can be very helpful if your model contains data that you need in order to compute a value to test against.

For example, let's say that you are storing the currentDay on your model, and you want to compute a date in the future to assert that a certain behaviour occurs.
This way you can access the data inside the current model coming from the current state of your program.

-}
withModel :
(model -> ProgramTest model msg effect -> ProgramTest model msg effect)
-> ProgramTest model msg effect
-> ProgramTest model msg effect
withModel fn programTest =
case programTest of
Created created ->
case created.state of
Err { reason } ->
FailedToCreate reason

Ok state ->
fn state.currentModel programTest

FailedToCreate failure ->
FailedToCreate failure


{-| Simulate the outcome of the last effect produced by the program being tested
by providing a function that can convert the last effect into `msg`s.

Expand Down