Fork me on GitHub
Rohan Nicholls19:11:44

Just out of interest is there a testing story that comes with hoplon?

Rohan Nicholls19:11:12

Usually when I am making tests in clojure I’m calling code with data and seeing what comes out the other end.

Rohan Nicholls19:11:47

If I do a (print (html)) or a (print (html(link :href "app.css" :rel "stylesheet" :type "text/css"))) I get back #<Element: HTML>

Rohan Nicholls19:11:11

This is not the most transparent thing I’ve ever seen. How do I open it up?

Rohan Nicholls19:11:03

I’m using print because I don’t seem to have access to a repl with the standard setup.


the html function returns an <html> DOM element, like document.createElement("HTML") in javascript


but you can test things just like you'd test any frontend, by testing the result of normal DOM operations


like using the DOM API to get the contents or inner html of a node

Rohan Nicholls19:11:52

Okay, cool thanks just tried it out and got a whole lot of stuff. Thanks.



(assert (= (.innerHTML (.getElementyId js/document "thingy")) "contents of the element"))


normally with tests you'd have some way to find a particular element in the DOM, and you'd then use the DOM API to test that the element has the properties or whatever that you want to test


here i find the element by id


but of course you can use more complex things like xpath for example, or the other DOM querying API functions in the rowser

Rohan Nicholls19:11:17

Okay, that sounds good. It is too bad when I do something like this (print (.-children (h1 "Hello, Hoplon!"))) The result can’t be cracked open in the browser the way it would with a …. oh just a sec. Hah! `(.log console (.-children (head (link :href “app.css” :rel “stylesheet” :type “text/css”))))`

Rohan Nicholls19:11:51

Gives me a pokable object in the console. Excellent. Good for exploring.

Rohan Nicholls19:11:22

Well, my favourite for extracting things is document.querySelector[All]

Rohan Nicholls19:11:52

But this is also all based on jQuery isn’t it? So, can you directly call well?


the queryselector method is part of the browser DOM API, you can use it anytime


also (print (.innerHTML (h1 "hi"))) would show you the html

Rohan Nicholls19:11:53

Yes, I tried that and got a big string, which can be really helpful, but since dom elements are being created, it is really handy to get a pokable object like the one console.log gives you. Best of both worlds.

Rohan Nicholls19:11:20

I’ve been doing a lot of work with angular for my job, and it wraps everything in layers of indirection. It is nice to be using something like clojurescript and to be so close to the dom elements.

Rohan Nicholls19:11:48

Taking some getting used to, but I’m starting to really enjoy this. I have not used clojure(script) in a few years.

Rohan Nicholls19:11:34

Oh, I also had a question about this page: When I tried the code, it says it does not know what local-storage is. I’m guessing I’m missing an import?

Rohan Nicholls19:11:11

And (yet) another question. If I want to add things to the wiki is it a pull request?


@rohan.nicholls regarding the wiki, feel free to edit the pages directly, you should be able to


(via Edit button)

Rohan Nicholls21:11:22

Okay thanks, there is no submission system?


no we trust you 😄


but if you want feedback on anything you wrote feel free to link here, we can look