hoplon

The :hoplon: ClojureScript Web Framework - http://hoplon.io/
Rohan Nicholls 2019-11-05T19:33:44.000900Z

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

Rohan Nicholls 2019-11-05T19:34:12.001500Z

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

Rohan Nicholls 2019-11-05T19:36:47.002700Z

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 Nicholls 2019-11-05T19:37:11.003300Z

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

Rohan Nicholls 2019-11-05T19:38:03.004300Z

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

micha 2019-11-05T19:38:41.004800Z

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

Rohan Nicholls 2019-11-05T19:39:28.005800Z

Ah, okay.

micha 2019-11-05T19:40:01.006400Z

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

micha 2019-11-05T19:40:14.006800Z

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

Rohan Nicholls 2019-11-05T19:41:52.007500Z

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

micha 2019-11-05T19:42:59.008700Z

like

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

micha 2019-11-05T19:43:48.009900Z

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

micha 2019-11-05T19:44:13.010400Z

here i find the element by id

micha 2019-11-05T19:44:47.011300Z

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

Rohan Nicholls 2019-11-05T19:46:17.011900Z

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 Nicholls 2019-11-05T19:46:51.012500Z

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

Rohan Nicholls 2019-11-05T19:47:22.013100Z

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

Rohan Nicholls 2019-11-05T19:47:52.013800Z

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

micha 2019-11-05T19:48:33.014400Z

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

micha 2019-11-05T19:49:05.015Z

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

Rohan Nicholls 2019-11-05T19:53:53.016400Z

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 Nicholls 2019-11-05T19:55:20.018Z

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 Nicholls 2019-11-05T19:55:48.018600Z

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

Rohan Nicholls 2019-11-05T19:56:34.019500Z

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 Nicholls 2019-11-05T19:57:11.020200Z

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

2019-11-05T20:39:49.020500Z

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

2019-11-05T20:39:55.020700Z

(via Edit button)

Rohan Nicholls 2019-11-05T21:50:22.021300Z

Okay thanks, there is no submission system?

2019-11-05T21:53:38.021500Z

no we trust you 😄

2019-11-05T21:53:47.021800Z

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