Update fx-test fixtures to use re-frame.core/make-restore-fn & update docs

This commit is contained in:
hipitihop 2016-08-24 10:44:21 +10:00
parent cdf26ca3d0
commit 733ad218a2
3 changed files with 22 additions and 21 deletions

View File

@ -266,14 +266,13 @@ Want to stub out the `:dispatch` effect? Do this:
If your test does alter registered effect handlers, and you are using `cljs.test`,
then you can use a `fixture` to restore all effect handlers at the end of your test:
```clj
(defn re-frame-fixture
[f]
(let [restore-re-frame-fn (re-frame.core/make-restore-fn)]
(try
(f)
(finally (restore-re-frame-fn)))))
(cljs.test/use-fixtures :each re-frame-fixture)
(defn fixture-re-frame
[]
(let [restore-re-frame (atom nil)]
{:before #(reset! restore-re-frame (re-frame.core/make-restore-fn))
:after #(@restore-re-frame)}))
(use-fixtures :each (fixture-re-frame))
```
`re-frame.core/make-restore-fn` creates a checkpoint for re-frame state (including

View File

@ -243,14 +243,13 @@ In your test, you'd mock out the cofx handler:
If your test does alter registered coeffect handlers, and you are using `cljs.test`,
then you can use a `fixture` to restore all coeffects at the end of your test:
```clj
(defn re-frame-fixture
[f]
(let [restore-re-frame-fn (re-frame.core/make-restore-fn)]
(try
(f)
(finally (restore-re-frame-fn)))))
(cljs.test/use-fixtures :each re-frame-fixture)
(defn fixture-re-frame
[]
(let [restore-re-frame (atom nil)]
{:before #(reset! restore-re-frame (re-frame.core/make-restore-fn))
:after #(@restore-re-frame)}))
(use-fixtures :each (fixture-re-frame))
```
`re-frame.core/make-restore-fn` creates a checkpoint for re-frame state (including

View File

@ -7,12 +7,15 @@
;; ---- FIXTURES ---------------------------------------------------------------
(defn teardown! []
; cleanup up our handlers
(doseq [event [::later-test ::watcher]]
(re-frame/clear-event event)))
;; This fixture uses the re-frame.core/make-restore-fn to checkpoint and reset
;; to cleanup any dynamically registered handlers from our tests.
(defn fixture-re-frame
[]
(let [restore-re-frame (atom nil)]
{:before #(reset! restore-re-frame (re-frame.core/make-restore-fn))
:after #(@restore-re-frame)}))
(use-fixtures :each {:after teardown!})
(use-fixtures :each (fixture-re-frame))
;; ---- TESTS ------------------------------------------------------------------