This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-22
Channels
- # admin-announcements (25)
- # beginners (60)
- # boot (277)
- # cider (5)
- # cljs-dev (3)
- # cljsrn (2)
- # clojure (82)
- # clojure-art (15)
- # clojure-berlin (2)
- # clojure-boston (1)
- # clojure-italy (40)
- # clojure-russia (118)
- # clojurebridge (1)
- # clojurecup (1)
- # clojurescript (82)
- # component (3)
- # cursive (31)
- # datavis (9)
- # datomic (39)
- # editors (1)
- # editors-rus (9)
- # emacs (15)
- # hoplon (50)
- # ldnclj (2)
- # leiningen (4)
- # off-topic (9)
- # om (123)
- # re-frame (28)
- # reagent (7)
- # vim (1)
- # yada (3)
Hi, I'm trying to write a test for a simple reagent component, with a textbox: (defn choose-city-component [] (let [inner-state (r/atom {:text ""})] (fn [] [:div [:input#txt_city { :type "text" :value (@inner-state :text) :on-change #(swap! inner-state assoc :text (-> % .-target .-value)) ... (deftest choose-city-component-test-out ;;GIVEN render component in test (let [comp (r/render-component [w/choose-city-component] (. js/document (getElementById "test")))] ;;WHEN changing the city (let [$txt_city ($ :#txt_city)] (val $txt_city "london") (trigger $txt_city :change ) basically rendering the component in a div, then using jquery (jayq) trying to simulate an on-change on the text box. Can anyone come with a better idea? Thank you
I answered my own problem by using cljs-react-test, which was designed for om but it works with reagent as well
(deftest choose-city-component-test-out (let [comp (r/render-component [w/choose-city-component] (. js/document (getElementById "test"))) expected-invocations (atom [])] (with-redefs [weather-app.core/fetch-weather #(swap! expected-invocations conj %)] ;;GIVEN render component in test ;;WHEN changing the city and submitting (sim/change (sel1 :#txt_city) {:target {:value "london"}}) (sim/click (sel1 :#btn_go) nil) ;;ASSERT london should be sent to fetch-weather (is (=["london"] @expected-invocations)) )))