reagent/test/reagenttest/utils.cljs

31 lines
870 B
Plaintext
Raw Normal View History

2017-11-08 18:47:56 +00:00
(ns reagenttest.utils
2019-12-17 20:50:14 +00:00
(:require [reagent.core :as r]
[reagent.dom :as rdom]))
2017-11-08 18:08:27 +00:00
(defn with-mounted-component [comp f]
(when r/is-client
(let [div (.createElement js/document "div")]
(try
2019-12-17 20:50:14 +00:00
(let [c (rdom/render comp div)]
2017-11-08 18:08:27 +00:00
(f c div))
(finally
2019-12-17 20:50:14 +00:00
(rdom/unmount-component-at-node div)
2017-11-08 18:08:27 +00:00
(r/flush))))))
(defn with-mounted-component-async [comp done f]
(when r/is-client
(let [div (.createElement js/document "div")
2019-12-17 20:50:14 +00:00
c (rdom/render comp div)]
2017-11-08 18:08:27 +00:00
(f c div (fn []
2019-12-17 20:50:14 +00:00
(rdom/unmount-component-at-node div)
2017-11-08 18:08:27 +00:00
(r/flush)
(done))))))
(defn run-fns-after-render [& fs]
((reduce (fn [cb f]
(fn []
(r/after-render (fn []
(f)
(cb)))))
(reverse fs))))