Fork me on GitHub
#clojurescript
<
2023-06-30
>
Tim Malov14:06:52

Hello everyone. I have probably very dumb question, but i really struggle to use cljs.test to test asynchronous code, so i would really appreciate any help. Even very basic example isn't working. I've wrote something like this:

(deftest test-test
  (t/async done
           (go (is (= 1 0)))
           (done)))
and builded it using shadow-cljs build:
:test
  {:target    :node-test
   :output-to *some-dir*
   :ns-regexp "Test$"
   :autorun   true}}}
and when i call shadow-cljs compile test nothing happens, it says "Ran 1 tests containing 0 assertions. 0 failures, 0 errors." How do i fix it?

delaguardo14:06:01

try this

(deftest test-test
  (t/async done
           (go (is (= 1 0))
               (done))))
If you write an asynchronous test the last value you return _must_ be the async block. from here - https://clojurescript.org/tools/testing#async-testing

thheller14:06:32

and (done) must be called when the async code is actually done. (go ...) does not wait for completion and instead schedules the body and the code after it runs immediately. so what you are seeing is (done) getting called before (go ..) even runs

Tim Malov14:06:11

Thank you. The (done) was outside the (go ...) so it didn't work - that was the problem.