Testing Halogen Application using custom Test monad without Aff and Effect

Hi all,

Could anybody point me so some resources or code examples of testing a Halogen App with custom test monad?

Many tutorials explain how to use an app monad (AppM) with Halogen. The AppM would usually implement the effects required in the app on top of the Aff monad. Before running, the resulting component is hoisted from AppM to Aff, then run using the runUI function.

I am looking for something similar buf for unit tests. I would like the tests not to run on top of Aff or Effect, but rather on top of a custom TestM monad. I could then hoist the component from type Component query input output TestM to lets say Component query input output Identity, but the question is what then? How can I run the Component query input output Identity component. Or how could I run the HalogenM state action slots output Identity a monad?

I believe the underlying monad must always be Aff. Depending on what you’re trying to test, you could define a TestM that keeps track of various state that you want to check before/after the component is ran.

1 Like

You only have to put it in Aff if you call runUI. It would be helpful to know exactly what kind of testing you want to do. You can certainly write your own HalogenM interpreter, but you are limited in what you can observe directly (at least safely) due to the existential nature of Components (the state type is opaque after the Component is constructed).

Some time ago I was experimenting with testing a Halogen component using a custom (test) driver:

I hope you find it useful.


Thanks, the examples were quite useful.

1 Like

In general, I would like to mock the effects, then privide a list of Actions as an input, and assert that the expected effects were executed. I think I figured out how to do that withtout running the HalogenM, by just switching the HalogenM with a TestM monad in tests.