core_test.cljs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. (ns web-client.core-spec
  2. (:require-macros [speclj.core :refer [describe it should= should should-not]])
  3. (:require [speclj.core]
  4. [reagent.core :as reagent :refer [atom]]
  5. [web-client.core :as rc]))
  6. (def isClient (not (nil? (try (.-document js/window)
  7. (catch js/Object e nil)))))
  8. (def rflush reagent/flush)
  9. (defn add-test-div [name]
  10. (let [doc js/document
  11. body (.-body js/document)
  12. div (.createElement doc "div")]
  13. (.appendChild body div)
  14. div))
  15. (defn with-mounted-component [comp f]
  16. (when isClient
  17. (let [div (add-test-div "_testreagent")]
  18. (let [comp (reagent/render-component comp div #(f comp div))]
  19. (reagent/unmount-component-at-node div)
  20. (reagent/flush)
  21. (.removeChild (.-body js/document) div)))))
  22. (defn found-in [re div]
  23. (let [res (.-innerHTML div)]
  24. (if (re-find re res)
  25. true
  26. (do (println "Not found: " res)
  27. false))))
  28. (describe "test home"
  29. (it "contains 'Welcome to' in home page"
  30. (with-mounted-component (rc/home-page)
  31. (fn [c div]
  32. (should (found-in #"Welcome to" div))))))