Add a test for component-path

This commit is contained in:
Dan Holmsand 2015-08-30 18:29:27 +02:00
parent 10562cfb9d
commit 3defd24c35
2 changed files with 15 additions and 3 deletions

View File

@ -289,8 +289,8 @@ the result can be compared with ="
(util/partial-ifn. f args nil))
(defn component-path
;;; Try to return the path of component c. Maybe useful for debugging
;;; and error reporting, but may break with future versions of React.
;;; Thus component-path may return nil.
;; Try to return the path of component c as a string.
;; Maybe useful for debugging and error reporting, but may break
;; with future versions of React (and return nil).
[c]
(comp/component-path c))

View File

@ -540,3 +540,15 @@
(r/force-update (:c2 @comps) true)
(is (= @v {:v1 3 :v2 3}))))))
(deftest test-component-path
(let [a (atom nil)
tc (r/create-class {:display-name "atestcomponent"
:render (fn []
(let [c (r/current-component)]
(reset! a (r/component-path c))
[:div]))})]
(with-mounted-component [tc]
(fn [c]
(is (seq @a))
(is (re-find #"atestcomponent" @a) "component-path should work")))))