From 4a8ac5cd83bda15fffa0a9d7416a204c4dc6475e Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Fri, 27 Apr 2018 23:17:25 +0300 Subject: [PATCH] Fix problem with custom HTML element property name code Custom HTML element property name code accidentally modified cache object for normal HTML elements, which can cause Reagent to lose correct mappings for properties like className, htmlFor and charSet. --- src/reagent/impl/template.cljs | 2 +- test/reagent/impl/template_test.cljs | 20 ++++++++++++++++++++ test/reagenttest/runtests.cljs | 6 +++--- 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 test/reagent/impl/template_test.cljs diff --git a/src/reagent/impl/template.cljs b/src/reagent/impl/template.cljs index 02e61aa..73cebef 100644 --- a/src/reagent/impl/template.cljs +++ b/src/reagent/impl/template.cljs @@ -82,7 +82,7 @@ (if (named? k) (if-some [k' (cache-get custom-prop-name-cache (name k))] k' - (aset prop-name-cache (name k) + (aset custom-prop-name-cache (name k) (util/dash-to-camel k))) k)) diff --git a/test/reagent/impl/template_test.cljs b/test/reagent/impl/template_test.cljs new file mode 100644 index 0000000..92d51f0 --- /dev/null +++ b/test/reagent/impl/template_test.cljs @@ -0,0 +1,20 @@ +(ns reagent.impl.template-test + (:require [clojure.test :as t :refer [deftest is testing]] + [reagent.impl.template :as tmpl] + [goog.object :as gobj])) + +(deftest cached-prop-name + (is (= "className" + (tmpl/cached-prop-name :class)))) + +(deftest cached-custom-prop-name + (is (= "class" + (tmpl/cached-custom-prop-name :class)))) + +(deftest convert-props-test + (is (gobj/equals #js {:className "a"} + (tmpl/convert-props {:class "a"} #js {:id nil :custom false}))) + (is (gobj/equals #js {:class "a"} + (tmpl/convert-props {:class "a"} #js {:id nil :custom true}))) + (is (gobj/equals #js {:className "a b" :id "a"} + (tmpl/convert-props {:class "b"} #js {:id "a" :class "a" :custom false})))) diff --git a/test/reagenttest/runtests.cljs b/test/reagenttest/runtests.cljs index 92e087a..b32d68a 100644 --- a/test/reagenttest/runtests.cljs +++ b/test/reagenttest/runtests.cljs @@ -7,6 +7,7 @@ [reagenttest.testtrack] [reagenttest.testwithlet] [reagenttest.testwrap] + [reagent.impl.template-test] [cljs.test :as test] [doo.runner :as doo :include-macros true] [reagent.core :as r] @@ -21,8 +22,7 @@ :color :#aaa}) (defn all-tests [] - #_(test/run-tests 'reagenttest.testratomasync) - (test/run-all-tests #"reagenttest.test.*")) + (test/run-all-tests #"(reagenttest\.test.*|reagent\..*-test)")) (defmethod test/report [::test/default :summary] [m] ;; ClojureScript 2814 doesn't return anything from run-tests @@ -56,4 +56,4 @@ (run-tests) [#'test-output-mini])) -(doo/doo-all-tests #"reagenttest.test.*") +(doo/doo-all-tests #"(reagenttest\.test.*|reagent\..*-test)")