reagent/test/reagenttest/utils.cljs

38 lines
974 B
Plaintext
Raw Normal View History

2017-11-08 18:47:56 +00:00
(ns reagenttest.utils
2017-11-08 18:08:27 +00:00
(:require [reagent.core :as r]))
(defn with-mounted-component [comp f]
(when r/is-client
(let [div (.createElement js/document "div")]
(try
(let [c (r/render comp div)]
(f c div))
(finally
(r/unmount-component-at-node div)
(r/flush))))))
(defn with-mounted-component-async [comp done f]
(when r/is-client
(let [div (.createElement js/document "div")
c (r/render comp div)]
(f c div (fn []
(r/unmount-component-at-node div)
(r/flush)
(done))))))
(defn run-fns-after-render [& fs]
((reduce (fn [cb f]
(fn []
(r/after-render (fn []
(f)
(cb)))))
(reverse fs))))
(defn found-in [re div]
(let [res (.-innerHTML div)]
(if (re-find re res)
true
(do (println "Not found: " res)
false))))