Modify test to check for missing fx handler
This commit is contained in:
parent
fad4e7315b
commit
f1337bcb6b
|
@ -4,7 +4,8 @@
|
|||
[re-frame.core :as re-frame]
|
||||
[re-frame.fx]
|
||||
[re-frame.interop :refer [set-timeout!]]
|
||||
[re-frame.loggers :as log]))
|
||||
[re-frame.loggers :as log]
|
||||
[clojure.string :as str]))
|
||||
|
||||
;; ---- FIXTURES ---------------------------------------------------------------
|
||||
|
||||
|
@ -16,13 +17,7 @@
|
|||
{:before #(reset! restore-re-frame (re-frame.core/make-restore-fn))
|
||||
:after #(@restore-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))
|
||||
(use-fixtures :each (fixture-re-frame))
|
||||
|
||||
;; ---- TESTS ------------------------------------------------------------------
|
||||
|
||||
|
@ -51,22 +46,19 @@
|
|||
;; kick off main handler
|
||||
(re-frame/dispatch [::later-test]))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::missing-handler-test
|
||||
(fn [_world _event-v]
|
||||
{:fx-not-exist [:nothing :here]}))
|
||||
|
||||
(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))))
|
||||
(let [logs (atom [])
|
||||
log-fn (fn [& args] (swap! logs conj (str/join args)))
|
||||
original-loggers (log/get-loggers)]
|
||||
(try
|
||||
(log/set-loggers! {:error log-fn})
|
||||
(re-frame/dispatch-sync [::missing-handler-test])
|
||||
(is (re-matches #"re-frame: no :fx handler registered for::fx-not-exist" (first @logs)))
|
||||
(is (= (count @logs) 1))
|
||||
(finally
|
||||
(log/set-loggers! original-loggers)))))
|
||||
|
|
Loading…
Reference in New Issue