4
votes

While running my tests with lein doo phantom, I receive a -1 status response and an empty string as the body. However, when I run the test in the repl, I am able to retrieve the request data with a 200 status response and the appropriate data in the body. Is this because a manytomany channel is being returned first as mentioned below, thus giving me the inappropriate response? If so, how could I account for this?

https://github.com/r0man/cljs-http#async-response-handling

I also thought maybe I need to use a timeout to wait for the request to complete. If so, how would I apply that appropriately with my existing code? It looks like cljs-http has :timeout as a parameter but I haven't been ably to get it to work appropriately (assuming this is the cause of the issue).

(deftest test-async
 (async done
      (go (let [response (<! (http/get "http://localhost:3000/api/user/1"
                                          {:with-credentials? false
                                           :query-params {"id" 1}}))]
            (is (= {:status 200}
                   (select-keys response [:status]))))
          (done))))
1

1 Answers

2
votes

Since you are running your test under phantomjs. Phantomjs default disable cross domain XHR access and your tests js are running on localhost,all external ajax calls are denied.

you can set the --web-security=false to allow your test to do cross domain ajax.

In your project.clj add this

:doo {:paths {:phantom "phantomjs --web-security=false"}}

more info about phantomjs

http://phantomjs.org/api/command-line.html