Fork me on GitHub
#re-frame
<
2024-06-03
>
mll09:06:01

Hi all! I am starting to write tests for my re-frame app. I have read all the docs on testing. I have decided to be using day8.re-frame/test to test the whole system in addition to standard unit tests of particular handlers and have the following question:

I use effects to do http queries and some custom effects to do some other stuff. How can I mock effects? What I mean is that when I do http query the effect dispatches some events on success/failure and I would like them to be dispatched with mocked data and possibly a delay. I use rf-test/run-test-async, but still no idea how to mock effects. I use [day8.re-frame/http-fx "0.2.4"] for http.

p-himik09:06:52

Everything in re-frame that you register with reg-* functions can be registered again, overriding the previous value. So if somewhere you have

(rf/reg-fx :http the-actual-handler)
you can do
(rf/reg-fx :http the-mocked-version)
as a preparation step for tests. But note that it's a global registry, there's no way to mock it per-test or unmock it without re-registering the original handler.

mll09:06:47

Ok, thanks!