These are chat archives for got-lambda/expression

15th
Sep 2016
Magnus Therning
@magthe
Sep 15 2016 05:36
I do like the lime one :)
Jean-Louis Giordano
@Jell
Sep 15 2016 09:19
@magthe oups might be a bit too late, but if possible would you rather have the lime?
you have 5min to answer :)
Magnus Therning
@magthe
Sep 15 2016 11:27
@Jell, time's up.... but no, I still want the sand one :)
Jean-Louis Giordano
@Jell
Sep 15 2016 11:29
:) good good
Magnus Therning
@magthe
Sep 15 2016 11:43
@Jell, @suvash and other ClojureScript devs... I've written unit tests for my state and its manipulation functions, now I'd like to write some tests for my remote calls (they use ajax.core), how do you do that sort of thing?
Jean-Louis Giordano
@Jell
Sep 15 2016 11:48
we've used various approaches: stubs using with-redef, have separate http component for test that has the same interface but with a fixed set of expected requests and results (we're using https://github.com/stuartsierra/component), but also starting a small webserver using jetty/compojure (also with a fixed set of expected requests and responses). The second option is a bit more involved as you can't really use lein-doo, you need to setup your own "end-to-end" integration test.
we also do end-to-end tests from our API server that uses a "prodution" build of the client app
ah of course, depends on your setup. If you have a full-stack project (with server and client) things are usually simpler
in our case the client and the server are two different projects
Magnus Therning
@magthe
Sep 15 2016 11:51
I only want something small to begin with, just to verify the data passed, I'm thinking mocking ajax.core/ajax-request basically :)
Jean-Louis Giordano
@Jell
Sep 15 2016 11:52
yeah mocking is trivial when you use components
without components you have to with-redef
you can implement a Protocol implemented by your components
Magnus Therning
@magthe
Sep 15 2016 11:52
are you talking about binding in deftest?
Jean-Louis Giordano
@Jell
Sep 15 2016 11:52
yes
Magnus Therning
@magthe
Sep 15 2016 11:53
that's supported in cljs.test then?
(I'm still struggling with finding docs)
Jean-Louis Giordano
@Jell
Sep 15 2016 11:53
with-redef?
that's a built-in clojure thing
I think for binding you have to declare your vars ^:dynamic
with-redefs literally redefines those
you could use binding as well I suppose, I try to avoid dynamic scoping in general
Jean-Louis Giordano
@Jell
Sep 15 2016 12:00
(binding is also a core clojure function)
Magnus Therning
@magthe
Sep 15 2016 12:51
ah, finally I made binding work... I'm not so sure I think it's elegant though, haha
Magnus Therning
@magthe
Sep 15 2016 13:03
and I get warnings on lack of ^:dynamic, just as @Jell said I would
with-redefs FTW it seems :)
Jean-Louis Giordano
@Jell
Sep 15 2016 13:10
:thumbsup:
Magnus Therning
@magthe
Sep 15 2016 13:13
that's nice, it means I can test yet another part of the cljs code... I still haven't dared diving into testing of the reagent-using code
Jean-Louis Giordano
@Jell
Sep 15 2016 13:51
we use a wrapper around react test utils https://github.com/bensu/cljs-react-test
you can test components by mounting them on a fake dom element
Magnus Therning
@magthe
Sep 15 2016 14:03
hmm, sounds complicated... it feels like I'll be putting that off until I feel sick and tired of C/C++/Python (which happens rather often actuall)
Jean-Louis Giordano
@Jell
Sep 15 2016 18:28
if you want to know the deep differences between with-redefs and binding: http://blog.cognitect.com/blog/2016/9/15/works-on-my-machine-understanding-var-bindings-and-roots
funny that this blog post showed up literally today!