Fork me on GitHub
#cljsrn
<
2017-03-24
>
seantempesta02:03:37

Have anyone found a good way to test cljsrn apps? Preferably using spec? Any tips would be appreciated. I’m thinking I can use test.check for all non-react functions, but I’d like to do UI testing (probably end-to-end) too.

vikeri11:03:40

@seantempesta What we’re doing is using enzyme and shallow-render the components. That will not generate anything useful but at least it will throw if there are any js-errors. But fb have released a new snapshot test feature for jest that would probably be more useful: https://facebook.github.io/jest/docs/tutorial-react-native.html

vikeri11:03:41

We’re doing this for spec tests:

(defmacro generative-tests
  "Takes a list of fn symbols and runs generative tests on them"
  [fn-syms]
  `(let [opts#     {:clojure.test.check/opts
                    {:num-tests 1}}
         long-res# (cljs.spec.test/check ~fn-syms opts#)
         res#      (cljs.spec.test/summarize-results
                     long-res#)]
     (cljs.test/is (-> ~fn-syms
                       empty?
                       not)
                   "A namespace was empty")
     (cljs.test/is (not (or (:check-failed res#)
                            (:check-threw res#)
                            (:instrument res#))) (str "Spec failed for "
                                                      (map :sym (filter :failure long-res#))))))

(s/fdef generative-tests
        :args (s/cat :syms (s/coll-of any?)))

(defn- gen-test
  ([n] (gen-test n #{}))
  ([n {:keys [exclude]}]
   `(generative-tests (clojure.set/difference
                        (enumerate-namespace ~n)
                        ~exclude))))

(defmacro gen-test-ns
  "Takes a ns and optionally excluded syms and runs generative tests for all the
   functions"
  [& args]
  (apply gen-test args))

mozinator217:03:02

I wish he could share more of the technical details