Just out of interest is there a testing story that comes with hoplon?
Usually when I am making tests in clojure I’m calling code with data and seeing what comes out the other end.
If I do a (print (html))
or a (print (html(link :href "app.css" :rel "stylesheet" :type "text/css")))
I get back #<Element: HTML>
This is not the most transparent thing I’ve ever seen. How do I open it up?
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
Ah, okay.
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
Okay, cool thanks just tried it out and got a whole lot of stuff. Thanks.
like
(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
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”))))`
Gives me a pokable object in the console. Excellent. Good for exploring.
Well, my favourite for extracting things is document.querySelector[All]
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
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.
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.
Taking some getting used to, but I’m starting to really enjoy this. I have not used clojure(script) in a few years.
Oh, I also had a question about this page:
https://github.com/hoplon/hoplon/wiki/Storage-Cells
When I tried the code, it says it does not know what local-storage
is. I’m guessing I’m missing an import?
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)
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