Fork me on GitHub
#testing
<
2016-03-08
>
rickmoynihan00:03:21

@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.

gadfly36120:03:38

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

nberger20:03:51

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

gadfly36120:03:16

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 (= ... )))

nberger20:03:29

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

nberger20:03:45

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

gadfly36120:03:22

ahh that makes sense, thank you!

nberger20:03:35

don't worry

nberger20:03:17

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

gadfly36120:03:34

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