This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-03
Channels
- # beginners (20)
- # boot (407)
- # cider (17)
- # cljs-dev (29)
- # cljsrn (33)
- # clojure (169)
- # clojure-greece (17)
- # clojure-russia (47)
- # clojure-spec (40)
- # clojure-uk (81)
- # clojurescript (64)
- # clr (3)
- # copenhagen-clojurians (3)
- # core-async (1)
- # cursive (28)
- # datomic (26)
- # editors-rus (4)
- # emacs (10)
- # events (1)
- # figwheel (1)
- # funcool (1)
- # hoplon (82)
- # jobs (1)
- # klipse (10)
- # lein-figwheel (26)
- # leiningen (1)
- # off-topic (2)
- # om (153)
- # overtone (2)
- # pedestal (15)
- # proton (1)
- # re-frame (6)
- # ring-swagger (1)
- # rum (1)
- # slack-help (4)
- # untangled (56)
- # vim (24)
- # yada (2)
hey, can someone tell me why this fails?
(deftest input-fn
(let [c (j/cell nil)
f #(reset! c true)
i (h/input :input f)
$i (js/jQuery i)]
(is (nil? @c))
(.trigger $i "input")
(is (true? @c))))
try
(deftest input-fn
(async done
(let [c (j/cell nil)
f #(reset! c true)
i (h/input :input f)
$i (js/jQuery i)]
(is (nil? @c))
(.trigger $i "input")
(js/setTimeout #(do (is (true? @c)) (done)) 0)))
oh really?
@thedavidmeister event handlers are triggered in a async way.
but this passes
(deftest input-cell
(let [c (j/cell nil)
i (h/input :c c)
$i (js/jQuery i)]
(is (not (.attr $i "c")))
(reset! c true)
(is (.attr $i "c"))))
i suppose that’s right
that is an interesting article, but i’m going to read it later 😛
another way would be to set an event handler, then trigger it
like before calling .trigger
, set up a function containing an (is ..)
via (.on $i ...)
basically a handler for the event you will trigger, with a test inside
oh yeah
so the is
becomes the event handler
(deftest input-fn
(async done
(let [c (j/cell nil)
f #(reset! c true)
i (h/input :click f)
$i (js/jQuery i)]
(is (nil? @c))
(.click $i)
(h/with-timeout 0 (do (is (= true @c))
(done))))))
not working
i’m missing something obvious i think
FAIL in (input-fn) (:)
expected: (= true (clojure.core/deref c))
actual: (not (= true nil))
like this?
(deftest input-fn
(async done
(let [c (j/cell nil)
f #(prn "foo")
i (h/input :click f)
$i (js/jQuery i)]
(is (nil? @c))
(.trigger $i "click")
(h/with-timeout 100 (do (is (= true @c))
(done))))))
didn’t print anything 😕
oh right
(deftest input-fn
(async done
(let [c (j/cell nil)
f #(prn "foo")
i (h/input)
$i (js/jQuery i)]
(.on $i "click" f)
(is (nil? @c))
(.trigger $i "click")
(h/with-timeout 100 (do (is (= true @c))
(done))))))
prints foo
(deftest input-fn
(async done
(let [c (j/cell nil)
f #(reset! c true)
i (h/input)
$i (js/jQuery i)]
(.on $i "click" f)
(is (nil? @c))
(.trigger $i "click")
(h/with-timeout 100 (do (is (= true @c))
(done))))))
passes tests
that’s weird
i thought Hoplon was just jquery
alpha16?
i feel like this should be a test in hoplon, lol
@dm3 so what’s the require you mentioned?
(deftest input-fn
(async done
(let [c (j/cell nil)
f #(reset! c true)
i (h/input :click f)
e (.createEvent js/document "HTMLEvents")]
(.initEvent e "click" true false)
(is (nil? @c))
(.dispatchEvent i e)
(h/with-timeout 0 (do (is (= true @c))
(done))))))
@thedavidmeister I haven't really used that myself 🙂 I think boot-hoplon
has a --refer
option for that
this fails too
is this a bug in hoplon though?
it’s just an input
(prn (.outerHTML i))
= <input>
i removed all the jQuery, and manually made it pass
(deftest input-fn
(async done
(let [c (j/cell nil)
f #(reset! c true)
i (h/input)
e (.createEvent js/document "HTMLEvents")]
(.addEventListener i "click" f)
(.initEvent e "click" true false)
(is (nil? @c))
(.dispatchEvent i e)
(h/with-timeout 0 (do (is (= true @c))
(done))))))
so i think something is wrong with hoplon?
(defmethod on! ::default
[elem event callback]
(when-dom elem #(.addEventListener elem (name event) callback)))
looks like the only bit that is different is the when-dom
call
(defn when-dom [this f]
(if-not (instance? js/Element this)
(f)
(timeout
(fn doit []
(if (.contains (.-documentElement js/document) this) (f) (timeout doit 20))))))
(is (.contains (.-documentElement js/document) i))
= fail
it is isn’t it?
(prn (instance? js/Element i))
= true
that’s really bad for testing 😞
i wonder, do we really need to wait for the element to be in the DOM before binding event handlers to it?
my event handler seemed to work fine without being in the document
this makes me sad
i was hoping to replace 90% of the tests i wrote in selenium with faster cljs tests
i’m really tired, i have to go sleep
but maybe we can remove the with-dom
for this
@jumblerg @micha looks like this was probably added by one of you ^^, might be able to add some context here?
:thumbsup: