Trying to do TDD with Elm. Got stuck in the update function

In JS or TS people usually use async/await and mocks to do parts of the tests. I really dislike this approach and prefer the Elm way. But I’m struggling to find a nice pattern for my tests.

For example, when the user clicks a button or submit a form, a message is sent. I can easily test that. But I feel this is a very narrow scope for a test.
So next I usually test if the message does what it’s suppose do to, in a separated test. Is the update message catching this message? Is it updating the model as it’s supposed to and returning the right Cmd?

I find this a little strange, to have 2 tests for this. And making the assertions on the Cmd Msg of the update function is getting tricky.

What I am getting wrong here? And if you do TDD with Elm, what is your pattern to test this kind of cenario?

Hey @marciofrayze

elm-program-test and elm-spec are two tools that solve the problem you’re encountering.

I have no experience with elm-spec, but we covered elm-program-test in this Elm Radio episode.

Hope this helps.


Yeah, maybe I’m using the wrong tool. Makes sense. I’ll try it out. Thanks for the advice!

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.