Requiring Cljs.test In Klipse
Once again I'm saved by friends in the Clojurians slack channel! This time it was viebel who answered my question in the klipse room. I really love the simplicity and ease of app.klipse.tech because it gives you an instant Clojurescript scratchpad at your fingertips. My only issue was that I didn't know how to add other ClojureScript libraries. Viebel opened my eyes to the fact that it's actually incredicibly easy to add other Clojurescript libraries, and here's how you do it!
If you try to use deftest or is, two functions from the cljs.test namespace, you should can an error; something like, "I can't call deftest because I don't know what that is!". However, we can use the familiar require function to add our namespace. Interestingly, it seems that in ClojureScript we can't just add our functions from namespace into our current namespace as it's seen as "bad style". So it seems that we can either add our testing library :as another name or explicitly state the functions that we want to add to our current namespace.
And here's the, in my opinion nicer, syntax where we explicitly add deftest and is:
You might be confused that when you enter this code into klipse and the call simple-case as a function it returns nil and prints nothing. The first time I did this I was asking myself, "wait, did it even work?".
However, if we change one of these 1s to another number so that the assertion becomes false we should see a nice little "FAIL" message describing what's wrong.
Yeah, buddy! Now that you can easily add a unit testing library to any klipse session I hope you'll take the time to write some tests as you solve some toy problems with ClojureScript in klipse! :)
Your comment will be posted after it is approved.
Leave a Reply.
The posts on this site are written and maintained by Jim Lynch. About Jim...