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

**URL:** <https://discourse.elm-lang.org/t/trying-to-do-tdd-with-elm-got-stuck-in-the-update-function/8370>\
**Category:** Learn\
**Created:** [May 5, 2022, 2:47pm UTC](https://discourse.elm-lang.org/t/trying-to-do-tdd-with-elm-got-stuck-in-the-update-function/8370 "2022-05-05T14:47:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marciofrayze](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/marciofrayze/32/3494_2.png) [@marciofrayze](https://discourse.elm-lang.org/u/marciofrayze)\
**Post date:** [May 5, 2022, 2:47pm UTC](https://discourse.elm-lang.org/t/trying-to-do-tdd-with-elm-got-stuck-in-the-update-function/8370/1 "2022-05-05T14:47:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jfmengels](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/jfmengels/32/3124_2.png) [@jfmengels](https://discourse.elm-lang.org/u/jfmengels)\
**Post date:** [May 5, 2022, 3:37pm UTC](https://discourse.elm-lang.org/t/trying-to-do-tdd-with-elm-got-stuck-in-the-update-function/8370/2 "2022-05-05T15:37:02Z")

</div>

Hey @marciofrayze

[`elm-program-test`](https://elm-program-test.netlify.app/) and [`elm-spec`](https://package.elm-lang.org/packages/brian-watkins/elm-spec/latest/) 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](https://elm-radio.com/episode/elm-program-test).

Hope this helps.

---

<div class="post-metadata">

**Author:** ![marciofrayze](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/marciofrayze/32/3494_2.png) [@marciofrayze](https://discourse.elm-lang.org/u/marciofrayze)\
**Post date:** [May 6, 2022, 11:27am UTC](https://discourse.elm-lang.org/t/trying-to-do-tdd-with-elm-got-stuck-in-the-update-function/8370/3 "2022-05-06T11:27:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [May 16, 2022, 11:27am UTC](https://discourse.elm-lang.org/t/trying-to-do-tdd-with-elm-got-stuck-in-the-update-function/8370/4 "2022-05-16T11:27:56Z")

</div>

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