test logging of missing effect handlers
This commit is contained in:
parent
846a30e3f5
commit
e3c4da6249
|
@ -3,7 +3,8 @@
|
||||||
[cljs.test :refer-macros [is deftest async use-fixtures]]
|
[cljs.test :refer-macros [is deftest async use-fixtures]]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[re-frame.fx]
|
[re-frame.fx]
|
||||||
[re-frame.interop :refer [set-timeout!]]))
|
[re-frame.interop :refer [set-timeout!]]
|
||||||
|
[re-frame.loggers :as log]))
|
||||||
|
|
||||||
;; ---- FIXTURES ---------------------------------------------------------------
|
;; ---- FIXTURES ---------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -15,7 +16,13 @@
|
||||||
{:before #(reset! restore-re-frame (re-frame.core/make-restore-fn))
|
{:before #(reset! restore-re-frame (re-frame.core/make-restore-fn))
|
||||||
:after #(@restore-re-frame)}))
|
:after #(@restore-re-frame)}))
|
||||||
|
|
||||||
(use-fixtures :each (fixture-re-frame))
|
(defn fixture-logger
|
||||||
|
[]
|
||||||
|
(let [old-loggers (atom nil)]
|
||||||
|
{:before #(reset! old-loggers @@#'log/loggers)
|
||||||
|
:after #(reset! @#'log/loggers @old-loggers)}))
|
||||||
|
|
||||||
|
(use-fixtures :each (fixture-re-frame) (fixture-logger))
|
||||||
|
|
||||||
;; ---- TESTS ------------------------------------------------------------------
|
;; ---- TESTS ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -43,3 +50,23 @@
|
||||||
1000)
|
1000)
|
||||||
;; kick off main handler
|
;; kick off main handler
|
||||||
(re-frame/dispatch [::later-test]))))
|
(re-frame/dispatch [::later-test]))))
|
||||||
|
|
||||||
|
(deftest report-missing-handler
|
||||||
|
(let [logs (atom [])
|
||||||
|
log-fn (fn[& args] (swap! logs #(conj % (clojure.string/join args))))
|
||||||
|
logger (zipmap [:log :warn :error] (repeat log-fn))]
|
||||||
|
(log/set-loggers! logger)
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::missing-handler-test
|
||||||
|
(fn[_world _event-v]
|
||||||
|
{:dispatch [:do-not-exist :handler]}))
|
||||||
|
|
||||||
|
(re-frame/dispatch [::missing-handler-test])
|
||||||
|
|
||||||
|
(async done
|
||||||
|
(set-timeout!
|
||||||
|
(fn []
|
||||||
|
(is (re-matches #"re-frame: no :event handler.*:do-not-exist" (first @logs)))
|
||||||
|
(done))
|
||||||
|
2))))
|
||||||
|
|
Loading…
Reference in New Issue