This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-04
Channels
- # admin-announcements (36)
- # beginners (54)
- # boot (74)
- # cider (14)
- # cljs-dev (91)
- # clojure (197)
- # clojure-austin (1)
- # clojure-conj (3)
- # clojure-india (5)
- # clojure-japan (3)
- # clojurescript (111)
- # core-logic (12)
- # cursive (6)
- # datascript (3)
- # datomic (16)
- # devcards (26)
- # events (1)
- # funcool (11)
- # hoplon (63)
- # jobs (2)
- # ldnclj (10)
- # lein-figwheel (6)
- # luminus (5)
- # nginx (7)
- # nyc (3)
- # off-topic (1)
- # om (148)
- # onyx (122)
- # portland-or (5)
- # re-frame (3)
- # reagent (25)
- # yada (15)
I have a simple input using a r/atom:
(defn input-component [value]
[:input {:type "text"
:value @value
:placeholder "Enter some text"
:on-change #(reset! value (-> % .-target .-value))}])
I'm trying to write a test saying basically "If I change the value of the atom, the component should display the new value"My test is like that
(deftest input-component-test
(let [state (r/atom "")]
(render-to "#react-root" [app/input-component state])
(let [elem-input (aget (query "input") 0)]
(is (= (.-value elem-input)
""))
(is (= @state
""))
(swap! state (fn [] "something"))
(is (= (.-value elem-input)
"something")))))
And the result
FAIL in (input-component-test) (at http:418:14)
expected: (= (.-value elem-input) "something")
actual: (not (= "" "something"))
you can see it there http://www.webp.ch/boot-cljs-experiments/
@dgellow: [not 100% sure] - have you tried calling regent/flush
before doing the test. doing it should explicitly flush to DOM
also have a look at the test suite of reagent. This looks close to what you are doing: https://github.com/reagent-project/reagent/blob/master/test/reagenttest/testreagent.cljs#L108
Is there a documentation of reagent's api somewhere? I see a lot of references to reaction
and flush
in the code but no references to them in the README.md and the website.
ya. the API is lacking documentation. imho, the functions in reagent.core
have pretty good doc strings. There is a GH issue for it: https://github.com/reagent-project/reagent/issues/191
@rohit my tests work when I call to r/flush
after my swap!
's, thank you for your help!
here are the API docs: https://ducky427.github.io/reagent-docs
I've created a page on reagent's wiki with the link to your github page https://github.com/reagent-project/reagent/wiki/API-Documentation