No need to mount test divs to dom

This commit is contained in:
Juho Teperi 2017-10-14 13:06:10 +03:00
parent 36509f79ff
commit e0b8bd337b
2 changed files with 9 additions and 22 deletions

View File

@ -24,23 +24,15 @@
(def rflush r/flush) (def rflush r/flush)
(defn add-test-div [name]
(let [doc js/document
body (.-body js/document)
div (.createElement doc "div")]
(.appendChild body div)
div))
(defn with-mounted-component [comp f] (defn with-mounted-component [comp f]
(when isClient (when isClient
(let [div (add-test-div "_testreagent")] (let [div (.createElement js/document "div")]
(try (try
(let [c (r/render comp div)] (let [c (r/render comp div)]
(f c div)) (f c div))
(finally (finally
(r/unmount-component-at-node div) (r/unmount-component-at-node div)
(r/flush) (r/flush))))))
(.removeChild (.-body js/document) div))))))
(defn found-in [re div] (defn found-in [re div]
(let [res (.-innerHTML div)] (let [res (.-innerHTML div)]

View File

@ -3,20 +3,15 @@
[reagent.debug :refer-macros [dbg println log]] [reagent.debug :refer-macros [dbg println log]]
[reagent.core :as r])) [reagent.core :as r]))
(defn add-test-div [name]
(let [doc js/document
body (.-body js/document)
div (.createElement doc "div")]
(.appendChild body div)
div))
(defn with-mounted-component [comp f] (defn with-mounted-component [comp f]
(when r/is-client (when r/is-client
(let [div (add-test-div "_testreagent")] (let [div (.createElement js/document "div")]
(let [comp (r/render comp div #(f comp div))] (try
(let [c (r/render comp div)]
(f c div))
(finally
(r/unmount-component-at-node div) (r/unmount-component-at-node div)
(r/flush) (r/flush))))))
(.removeChild (.-body js/document) div)))))
(defn found-in [re div] (defn found-in [re div]
(let [res (.-innerHTML div)] (let [res (.-innerHTML div)]