mirror of https://github.com/status-im/reagent.git
Add test for child context
This commit is contained in:
parent
17351984a9
commit
a8ec0d219b
|
@ -29,7 +29,8 @@
|
||||||
[cljsjs/react-dom-server "16.1.0-0"]]}
|
[cljsjs/react-dom-server "16.1.0-0"]]}
|
||||||
|
|
||||||
:dev {:dependencies [[figwheel "0.5.14"]
|
:dev {:dependencies [[figwheel "0.5.14"]
|
||||||
[doo "0.1.8"]]
|
[doo "0.1.8"]
|
||||||
|
[cljsjs/prop-types "15.6.0-0"]]
|
||||||
:source-paths ["demo" "examples/todomvc/src" "examples/simple/src" "examples/geometry/src"]
|
:source-paths ["demo" "examples/todomvc/src" "examples/simple/src" "examples/geometry/src"]
|
||||||
:resource-paths ["site" "target/cljsbuild/client"]}}
|
:resource-paths ["site" "target/cljsbuild/client"]}}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@cljs-oss/module-deps": "1.1.1",
|
"@cljs-oss/module-deps": "1.1.1",
|
||||||
"create-react-class": "^15.6.2",
|
"create-react-class": "^15.6.2",
|
||||||
|
"prop-types": "^15.6.0",
|
||||||
"react": "^15.6.2",
|
"react": "^15.6.2",
|
||||||
"react-dom": "^15.6.2"
|
"react-dom": "^15.6.2"
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,7 +9,9 @@
|
||||||
[reagent.dom.server :as server]
|
[reagent.dom.server :as server]
|
||||||
[reagent.impl.util :as util]
|
[reagent.impl.util :as util]
|
||||||
[reagenttest.utils :as u :refer [with-mounted-component found-in]]
|
[reagenttest.utils :as u :refer [with-mounted-component found-in]]
|
||||||
[goog.string :as gstr]))
|
[goog.string :as gstr]
|
||||||
|
[goog.object :as gobj]
|
||||||
|
[prop-types :as prop-types]))
|
||||||
|
|
||||||
(def tests-done (atom {}))
|
(def tests-done (atom {}))
|
||||||
|
|
||||||
|
@ -1079,3 +1081,29 @@
|
||||||
(is (= "<i> </i>"
|
(is (= "<i> </i>"
|
||||||
(server/render-to-static-markup
|
(server/render-to-static-markup
|
||||||
[:i (gstr/unescapeEntities " ")]))))
|
[:i (gstr/unescapeEntities " ")]))))
|
||||||
|
|
||||||
|
(defn context-wrapper []
|
||||||
|
(r/create-class
|
||||||
|
{:get-child-context (fn []
|
||||||
|
(this-as this
|
||||||
|
#js {:foo "bar"}))
|
||||||
|
:child-context-types #js {:foo prop-types/string.isRequired}
|
||||||
|
:reagent-render (fn [child]
|
||||||
|
[:div
|
||||||
|
"parent,"
|
||||||
|
child])}))
|
||||||
|
|
||||||
|
(defn context-child []
|
||||||
|
(r/create-class
|
||||||
|
{:context-types #js {:foo prop-types/string.isRequired}
|
||||||
|
:reagent-render (fn []
|
||||||
|
(let [this (r/current-component)]
|
||||||
|
;; Context property name is not mangled, so need to use gobj/get to access property by string name
|
||||||
|
;; React extern handles context name.
|
||||||
|
[:div "child," (gobj/get (.-context this) "foo")]))}))
|
||||||
|
|
||||||
|
(deftest context-test
|
||||||
|
(with-mounted-component [context-wrapper [context-child]]
|
||||||
|
(fn [c div]
|
||||||
|
(is (= "parent,child,bar"
|
||||||
|
(.-innerText div))))))
|
||||||
|
|
Loading…
Reference in New Issue