testing

Testing tools, testing philosophy & methodology...
2016-03-08T00:14:21.000038Z

@bjr You could try: 1) Mark your deftests with metadata to define the groups... e.g. (deftest ^:functional functional-test ...) 2) In your fixture test that the function has the appropriate metadata. The difficulty is that the metadata exists on the deftest vars not on the functions - and the fixtures receive the functions themselves... So you'll have to look in the ns-map deref all the vars to find the functions and then build a new map from fn => (meta var) 3) then lookup your function in the map to access its meta data and compare the key. 4) If the key on the functions var is = to the key associated with the fixture - execute the fixture - otherwise just call the function.

gadfly361 2016-03-08T20:00:38.000039Z

Anyone have experience testing ajax calls with cljs.test? Looking for an example to peruse.

nberger 2016-03-08T20:07:51.000040Z

@gadfly361: are you going to do the actual requests, or are you thinking about mocking them? In any case you are probably going to use cljs.test/async, did you see it?

gadfly361 2016-03-08T20:13:16.000041Z

for the most part, ill be mocking the response from requests. Curious how to do an actual request in a test tho, just to know how. I saw async, and assume that's the secret sauce, but it didn't appear to run the ajax call. I did something along the lines of:

(deftest fake-test
   (async done
       (some-ajax-call)
      (done))
  (is (= ... )))

nberger 2016-03-08T20:15:29.000042Z

the thing is that you should call done only after all your assertions have run... and that's upon the request response usually... so if your ajax call accepts a callback, then you will usually have the assertions in the callback, and then you'll call done, still in the callback

nberger 2016-03-08T20:15:45.000043Z

if it returns a core.async chan, you'd have a go block, etc...

gadfly361 2016-03-08T20:16:22.000044Z

ahh that makes sense, thank you!

nberger 2016-03-08T20:16:35.000045Z

don't worry

nberger 2016-03-08T20:17:17.000046Z

about mocking, try to avoid it in async tests as most as possible :simple_smile:

gadfly361 2016-03-08T20:18:34.000047Z

sounds good, thanks :simple_smile: Need to do a little bit of refactoring and try this out

nberger 2016-03-08T20:18:53.000048Z

cool