bensu / doo

doo is a library and lein plugin to run cljs.test on different js environments.
Eclipse Public License 1.0
325 stars 63 forks source link

test-check's defscpec #118

Closed agzam closed 8 years ago

agzam commented 8 years ago

For some reason following code doesn't work:

  (require '[clojure.test.check.clojure-test :refer-macros [defspec]]
          '[clojure.spec :as s])

  (defspec foo-test 100
    (prop/for-all [m (s/gen ,,,)]
      ,,,))

throws messages like this:

  ERROR in (foo-test) (clojure$test$check$generators$call_gen@file:222:1)
  Uncaught exception, not in assertion.
  expected: nil
  actual: #object[TypeError TypeError: generator_fn is null]

This is the exact piece that doesn't work. The same thing works in CLJ and does work in CLJS when compiled .js is passed directly to Karma

(ns finops-admin.foo-test
  (:require 
   [clojure.test.check.clojure-test :refer-macros [defspec]]
   [clojure.test.check.properties :as prop]
   [clojure.test.check :as tc]
   [clojure.spec :as s]))

(defspec testing-foo 100
  (prop/for-all [v (s/gen (s/and string?))]
(< 0 (count v))))

;; and the following approach doesn't work either
(def pp
   (prop/for-all [v (s/gen (s/and string?))]
     (< 0 (count v))))

 (tc/quick-check pp 100)
bensu commented 8 years ago

Hi @agzam

Can you make an reproduction case that I could try?

agzam commented 8 years ago

@bensu https://github.com/agzam/try-doo-with-spec/blob/master/test/cljs/try_doo_with_spec/foo_test.cljs#L9 quick-check doesn't work either. Thanks again for helping me. I'll try adding to that another branch (which not using doo) where it works.

I really want to use doo though.

agzam commented 8 years ago

@bensu oh... wow... I think I have figured out this one as well! I am so happy it's not a problem with Doo! It's turned out to be this:

prop/for-all is a function (I think) based on a macro for-all*. So in order it to work (in CLJS) you actually need to have (require '[clojure.test.check.properties :refer-macros [for-all]]). Again, I might be totally wrong about function/macro thing, yet it seems to be working when required as shown.

Once again huuuuge, enormous, big thanks for helping me out! Sorry for bugging you with a non-existing problem (again). I'm glad though I have created this issue - if someone else stumbles on that, maybe finds this helpful.

bensu commented 8 years ago

I'm glad it worked out.