cemerick / clojurescript.test

A maximal port of `clojure.test` to ClojureScript. DEPRECATED
165 stars 32 forks source link

TestContext fails on async call #69

Closed fredericlb closed 9 years ago

fredericlb commented 10 years ago

Hi,

I am not really sure if this is really a bug or if I'm making a mistake but when running this test :

(deftest ^:async empty-db-is-of-length-0
  (go
   (reset-db)
   (let [c (core/all-docs db {"include-docs" true})
         res (<! c)]
     (is= (:total_rows res) 0))
   (done)))

i am told that th following assert failed : (instance? TestContext test-ctx)

however it looks to me that my code is quite close to the one concerning core.async in the README.

do you have any idea of the reason why this code snippet fails ?

thanks,

cemerick commented 10 years ago

Perhaps a dupe of #70. Queued, thanks.

Verneri commented 10 years ago

Using the example given in here gives the same result:

(defn- timeout-helper
  [test-context delay]
  (with-test-ctx test-context
    (let [now #(.getTime (js/Date.))
        t (now)]
      (js/setTimeout
        (fn []
          (is (>= (now) (+ t delay)))
          (done))
        delay))))

(deftest ^:async timeout
  (timeout-helper 2000))

printing the arguments of helper shows that context is 2000 and delay nil.

and cljs is version "0.0-2202" cljs.test version "0.3.1"

and the code is run in phantomjs

jonahkagan commented 10 years ago

@Verneri I found that explicitly passing in -test-ctx to timeout-helper solves the issue you're facing.

(deftest ^:async timeout
  (timeout-helper -test-ctx 2000))

Perhaps the example in the README was supposed to look like this originally?

cemerick commented 9 years ago

Does this still happen under ClojureScript 2411? #70 is no longer a problem under it (and maybe other more recent compiler versions?).

fredericlb commented 9 years ago

Yes it's fixed now ! Thanks