Skip to content

Instantly share code, notes, and snippets.

@bhb
Last active March 17, 2017 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhb/5dcb9ecdd6b3cda09b314516c36eaf49 to your computer and use it in GitHub Desktop.
Save bhb/5dcb9ecdd6b3cda09b314516c36eaf49 to your computer and use it in GitHub Desktop.
Example of inspecting core.async state in between tests
(ns radiator-react-native.app-test
(:require [cljs.core.async :as async :refer [<!]]
[cljs.core.async.impl.dispatch :as async.dispatch]
[cljs.test :refer [deftest testing is use-fixtures async]])
(:require-macros [cljs.core.async.macros :refer [go]]))
(enable-console-print!)
(def check-async-status
{:after (fn []
(prn {:queued? async.dispatch/queued?
:running? async.dispatch/running?
:task-count (.-length async.dispatch/tasks)}))})
(use-fixtures :each check-async-status)
(defn identity-chan
[x]
(let [c (async/chan 1)]
(go (>! c x)
(async/close! c))
c))
(deftest other-test
(is (= 1 1)))
;; after this test runs, I get {:queued? false, :running? false, :task-count 0}
(deftest test-identity-chan
(async done
(async/close! (go
(is (= (<! (identity-chan 42)) 42))
(done)))))
;; after this test runs, I get {:queued? true, :running? true, :task-count 0}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment