When I run my tests with lein doo phantom, I get a -1 status response and an empty string as a body. However, when I run the test in repl, I can get the request data with a status response of 200 and the corresponding data in the body. Is it because the first multi-channel channel is returned first, as indicated below, which gives me the wrong answer? If so, how can I explain 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 this with my existing code? It seems that cljs-http has: a timeout as a parameter, but I was not sure if it worked properly (assuming this is the cause of the problem).
(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))))
source
share