Introducing dillonkearns/elm-form - a new approach to Forms in Elm

I really like this library! I’ve been playing with it on and off this past week. One question that I have is what approach do you take to test the forms that you create?

I had a play today to see if I could get ProgramTest style tests working with this but I hit a couple of hurdles.

The first hurdle comes from the way events are handled within the form which means that using ProgramTest’s fillIn, clickButton etc. don’t work. ProgramTest expects simple event handlers to be added to the specific elements e.g the input/button and also don’t do anything fancy with data on the event where as elm-form attaches event handlers to the form and uses the event object to get field data. It’s possible to work around this by using simulateDomEvent but it results in fairly brittle tests that are closely tied to the event data structure elm-form expects.

The second hurdle I found came from the fact that elm-form returns Cmd’s when calling update. The ProgramTest approach depends on being able to know what a given effect value represents and subsequently avoids using Cmd’s directly because they are opaque. I may be wrong but I think this stopped me from being able to simulate progressing the form state.

After exploring I thought it would be good to take a step back and ask, how do you go about testing your forms?

2 Likes