Reagent client-side testing guide?

407 views
Skip to first unread message

Jonathon McKitrick

unread,
Mar 1, 2015, 3:01:15 PM3/1/15
to clojur...@googlegroups.com
I've seen a number of articles on how to set up Om client-side testing, but I've not found anything similar (yet) for Reagent. Can anyone point the way, or explain a setup that has worked for you?

Jonathon McKitrick

unread,
Mar 2, 2015, 8:44:58 AM3/2/15
to clojur...@googlegroups.com
Here's what I'm currently trying and failing with:

(defn new-id
([]
(str "container-" (gensym)))
([id]
(str "container-" id)))

(defn new-node
[id]
(-> (dommy/create-element "div")
(dommy/set-attr! "id" id)))

(defn append-node
[node]
(dommy/append! (dommy/sel1 js/document :body) node))

(defn container!
([]
(container! (new-id)))
([id]
(-> id
new-node
append-node)))

(deftest result-handlers
(testing "success"
(let [c (container! "foo")]
(reagent/render-component [u/success-component] (dommy/sel1 :#foo)))))

and here is the error:

ERROR in (util.test/result-handlers) (:)
Uncaught exception, not in assertion.
expected: nil
actual:
TypeError: instanceof called on an object with an invalid prototype property.
at resources/polyfill.js:13
at resources/public/js/unit-test.js:1894
at resources/public/js/unit-test.js:2033
at resources/public/js/unit-test.js:7316
at resources/public/js/unit-test.js:7275
at ReactDOMComponent_mountComponent (resources/public/js/unit-test.js:12373)
at resources/public/js/unit-test.js:6125
at ReactCompositeComponent_mountComponent (resources/public/js/unit-test.js:12373)
at resources/public/js/unit-test.js:5158
at resources/public/js/unit-test.js:15416
at resources/public/js/unit-test.js:5140
at resources/public/js/unit-test.js:11256
at ReactMount__renderNewRootComponent (resources/public/js/unit-test.js:12373)
at resources/public/js/unit-test.js:11325
at React_render (resources/public/js/unit-test.js:12373)
at render_component (resources/public/js/unit-test.js:51499)
at resources/public/js/unit-test.js:53504
at resources/public/js/unit-test.js:53511
at resources/public/js/unit-test.js:53498
at resources/public/js/unit-test.js:53509
at result_handlers_test (resources/public/js/unit-test.js:82465)
at resources/public/js/unit-test.js:81617
at resources/public/js/unit-test.js:81644
at resources/public/js/unit-test.js:81711
at default_fixture (resources/public/js/unit-test.js:81424)
at resources/public/js/unit-test.js:81713
at default_fixture (resources/public/js/unit-test.js:81424)

and here is the relevant bit from project.cljs:

:client-test {:cljsbuild
{:builds
{:test
{:source-paths ["src/cljs" "test/cljs"]
:compiler {:output-to "resources/public/js/unit-test.js"
:optimizations :whitespace
:pretty-print true
:preamble ^:replace ["jquery/jquery-2.1.1.min.js" "reagent/react.js"]}}}
:test-commands {"unit-test" ["phantomjs"
:runner "resources/polyfill.js" "resources/public/js/unit-test.js"]}}
:dependencies [[prismatic/dommy "1.0.0"]]}

ducky

unread,
Mar 2, 2015, 8:47:34 AM3/2/15
to clojur...@googlegroups.com
You can have a look here:

https://github.com/reagent-project/reagent-template

The reagent-template has a flag for generating basic testing setup.

Jonathon McKitrick

unread,
Mar 2, 2015, 8:52:44 AM3/2/15
to clojur...@googlegroups.com
How difficult is it to move an existing project into a template like this?


--
Jonathon McKitrick


--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to a topic in the Google Groups "ClojureScript" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojurescript/SqfxkbFDExE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

ducky

unread,
Mar 2, 2015, 9:32:33 AM3/2/15
to clojur...@googlegroups.com
I suggest that you generate a project with testing using reagent-template and then inspect its project.clj and the test folder to see whats needed.

It shouldn't be difficult to add the necessary things to your project.

Jonathon McKitrick

unread,
Mar 3, 2015, 10:07:00 AM3/3/15
to clojur...@googlegroups.com
I poked around, and found exactly what I needed in that template. Thanks!

ducky

unread,
Mar 3, 2015, 12:07:30 PM3/3/15
to clojur...@googlegroups.com
Thats great!

Jonathon McKitrick

unread,
Mar 5, 2015, 12:31:40 PM3/5/15
to clojur...@googlegroups.com
I just opened an issue in that same project you might have insight on.



--
Jonathon McKitrick

On Tue, Mar 3, 2015 at 12:07 PM, ducky <rohit.a...@gmail.com> wrote:
Thats great!
Reply all
Reply to author
Forward
0 new messages