-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Events bleed between tests using run-test-async
#13
Comments
I'm seeing this same problem. Specifically for me, I had some irrelevant dispatch-laters which were starting to bleed in to subsequent tests. I'm working around it with the following horror
And calling An official solution would be very, very welcome!! |
@jasich checking: is the solution simply that @danielneal yes, you'll have to stub out the
|
@mike-thompson-day8 definitely something like that. |
@danielneal Sorry, I edited/added-to my last answer at about the same time you responded. So you might not have seen everything I ended up putting in there (my bad, I know). Can you have another read of the above please. I think I see two different issues here (solved in different ways):
|
@mike-thompson-day8 Yes that sounds right! A stub of dispatch later (and any user defined fx that might leak via timeouts) would handle the slow bleed, and clearing the event queue should handle the fast bleed of events that are already queued up (has usually been just ~one pending event in my experience). |
@mike-thompson-day8 I'll go and do (2) right now - what should I do for (1) to call to clear the reframe event queue? Is that a change to re-frame-test or something I should be doing from my test code. |
@danielneal Once that's in place, then the macro |
As a first step, I've hastily added a new API function |
@mike-thompson-day8, I believe that clearing the queue at the end of |
Hello @mike-thompson-day8 and the maintainers. Firstly, thank you for your awesome work! Official fix is still relevant. My run-test-async don't finish, until I exclude tests for the code that uses dispatch later. I'm using slightly modified code from @danielneal, and tests seem to work. (They work even with the original piece). (def *timers (atom #{}))
(defn monkey-patch-reframe-timers!
"call me from your test runner"
[]
(rf/reg-event-fx :dispatch-later (fn [_]))
(set! re-frame.interop/set-timeout!
(fn [f ms]
(let [id (js/setTimeout f ms)]
(swap! *timers conj id)
id))))
(defn clear-timers!
"call me in the beginning of your deftests"
[]
(rf/purge-event-queue)
(doseq [t @*timers]
(js/clearTimeout t))
(reset! *timers #{})) I've tried just (purge-event-queue) in the beginning of my deftest's, it didn't help. Thanks again for the tools! |
I have a test where I want to check for one specific event using
rf-test/wait-for
. This event cascades some dispatches of other events, which seem to bleed into other async tests if I don't explicitly wait for them to occur. Ideally if the test ends re-frame-test would kill all pending events. My current workaround is to add await-for
at the end of the test for the last event in the event chain so that pending event's don't infect the other tests.The text was updated successfully, but these errors were encountered: