Add a way to get the model from a `ProgramTest`
- Dominant language
- Elm
- Stars
- 95
- Forks
- 28
- PR merge metrics
- No merged PRs in 30d
Description
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:
```elm
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:
```elm
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 :)
Contributor guide
Research direction
Start with the existing ProgramTest chaining entry points used by start, simulateHttpOk, clickButton, and expectViewHasNot, then compare how they expose or transform test state. Review the proposed withModel signature and verify that it can access the model before simulating the HTTP response. Done means a working model-access operation with coverage for the currentDate-style use case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elm
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100