From 3defd24c35952cf679f84a0d55e0135935095665 Mon Sep 17 00:00:00 2001 From: Dan Holmsand Date: Sun, 30 Aug 2015 18:29:27 +0200 Subject: [PATCH] Add a test for component-path --- src/reagent/core.cljs | 6 +++--- test/reagenttest/testreagent.cljs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/reagent/core.cljs b/src/reagent/core.cljs index 5853e5a..3e40c56 100644 --- a/src/reagent/core.cljs +++ b/src/reagent/core.cljs @@ -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)) diff --git a/test/reagenttest/testreagent.cljs b/test/reagenttest/testreagent.cljs index ec81bae..b51a1c2 100644 --- a/test/reagenttest/testreagent.cljs +++ b/test/reagenttest/testreagent.cljs @@ -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")))))