Skip to content

Commit

Permalink
Add test showing Reagent running disposed reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcompton committed Oct 26, 2016
1 parent dc7a2b9 commit 133d4c5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

:profiles {:test {:cljsbuild
{:builds {:client {:source-paths ["test"]
:notify-command ["node" "bin/gen-site.js"]
:compiler
{:main "reagenttest.runtests"}}}}}

Expand Down
38 changes: 31 additions & 7 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 @@ -461,3 +461,27 @@
(r/flush)
(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))))

0 comments on commit 133d4c5

Please sign in to comment.