Skip to content
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

Add test showing Reagent running disposed reactions #270

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 32 additions & 8 deletions test/reagenttest/testratom.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
(dispose co))
(let [!x (rv/atom 0)
!co (rv/make-reaction #(inc @!x) :auto-run true)]
(is (= 1 @!co) "CO has correct value on first deref")
(swap! !x inc)
(is (= 1 @!co) "CO has correct value on first deref")
(swap! !x inc)
(is (= 2 @!co) "CO auto-updates")
(dispose !co))
(is (= runs (running)))))
Expand All @@ -126,27 +126,27 @@
(is (= @res (+ 2 @a)))
(is (= @b-changed 1))
(is (= @c-changed 0))

(reset! a -1)
(is (= @res (+ 2 @a)))
(is (= @b-changed 2))
(is (= @c-changed 0))

(reset! a 2)
(is (= @res (+ 10 @a)))
(is (<= 2 @b-changed 3))
(is (= @c-changed 1))

(reset! a 3)
(is (= @res (+ 10 @a)))
(is (<= 2 @b-changed 3))
(is (= @c-changed 2))

(reset! a 3)
(is (= @res (+ 10 @a)))
(is (<= 2 @b-changed 3))
(is (= @c-changed 2))

(reset! a -1)
(is (= @res (+ 2 @a)))
(dispose res)
Expand Down Expand Up @@ -462,9 +462,33 @@
(dispose r1)
(is (= runs (running)))))

(deftest running-disposed-reactions
(let [ra (r/atom 0)
run-number (atom 0)
disposed? (atom false)
r1 (rv/make-reaction (fn []
(swap! run-number inc)
@ra)
:on-dispose (fn [] (reset! disposed? true)))]
(is (= @run-number 0))
@r1
(is (= @run-number 1))
(swap! ra inc)
(is (= @run-number 1))
@r1
(is (= @run-number 2))
(rv/dispose! r1)
(is (true? @disposed?))

(is (= @run-number 2))
(swap! ra inc)
@r1
;; An exception or error should be logged here as we are trying to deref a disposed reaction.
(is (= @run-number 2))))

(deftest ratom-with-meta
(let [value {:val 1}
meta-value {:meta-val 1}
state (with-meta (r/atom value) meta-value)]
(is (= (meta state) meta-value))
(is (= @state value))))
(is (= @state value))))