avh4 / elm-program-test

Test Elm programs
https://elm-program-test.netlify.com/
MIT License
93 stars 27 forks source link

Add a way to get the model from a `ProgramTest` #174

Open JasterV opened 1 year ago

JasterV commented 1 year ago

I'm storing some data inside the model that I would like to use on the tests to compute some values.

For example, I'm storing the currentDate inside the model, and later on I need the currentdate to mock an HTTP response.

So I would like to be able to do something like:

start
    |> ProgramTest.withModel
         (\model -> 
               ProgramTest.simulateHttpOk "POST" mockUrl (responseSuccess model.currentDate)
         )
       |> ProgramTest.clickButton "button"
       |> ProgramTest.expectViewHasNot [ Selector.id "test-id" ]

The signature of the function could be something like:

withModel : (model -> ProgramTest model msg effect -> ProgramTest model msg effect) -> ProgramTest model msg effect -> ProgramTest model msg effect

What do you think? If you agree I could even open a PR myself :)

JasterV commented 1 year ago

I feel this could be kinda related to #127 even though it is not exactly the same

JasterV commented 1 year ago

@avh4 is this library being maintained? Otherwise, are there any alternatives?