Fork me on GitHub
#hoplon
<
2019-11-05
>
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.

micha19:11:41

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

micha19:11:01

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

micha19:11:14

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.

micha19:11:59

like

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

micha19:11:48

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

micha19:11:13

here i find the element by id

micha19:11:47

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?

micha19:11:33

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

micha19:11:05

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: 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?

Rohan Nicholls19:11:11

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

alandipert20:11:49

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

alandipert20:11:55

(via Edit button)

Rohan Nicholls21:11:22

Okay thanks, there is no submission system?

alandipert21:11:38

no we trust you 😄

alandipert21:11:47

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