Fork me on GitHub
#clojurescript
<
2023-11-16
>
itaied10:11:15

Using cljs.test, how can I create multiple deftest based on a collection? In jest I could do this:

test.each(routes)("%s", async (route) => { ... }
Where each route is the name of the test. The problem with setting a single deftest with multiple assertions (like are) is pinpointing the exact test that failed. I think I can do it with a macro, but is there anything built in for it?

itaied10:11:57

It does conflict with async testing https://clojurescript.org/tools/testing#async-testing *NOTE:* You cannot have more than one async test per deftest form or only the first one will run.

p-himik11:11:39

Seems that can wrap all the testing forms with a single async form and call done only when every async route test is done.

p-himik11:11:22

Hmm, but it won't work if that async's function body uses other async things since testing needs for its body to be synchronous.

p-himik11:11:51

Some something like this is possible:

(defn some-async-fn [route]
  (js/Promise.resolve route))

(defn async-test-fn [route]
  (-> (some-async-fn route)
      (.then (fn [result]
               (t/testing "result is the route"
                 (t/is (= result route)))))))

(def routes [{:id :route-1} {:id :route-2}])

(t/deftest async-test
  (t/async done
    (let [promises (mapv async-test-fn routes)]
      (-> (js/Promise.all promises)
          (.then (fn [_]
                   (done)))))))

Aviv11:11:30

Hey, i’m using cljs-test, Inside a test, I have some promise that i’m using <p! to await for it. The promise is failing and i’m getting the error:

dev/out/cljs-runtime/cljs/core.cljs:11623
  (let [e (js/Error. message)]
          ^
Error: Promise error
    at new cljs$core$ExceptionInfo
anyone knows why the error isn’t printed? Thanks 🙏

🙌 1
cjohansen13:11:44

Is there some way I configure myself out of this problem?

[JSC_UNTRANSPILABLE] Cannot convert ECMASCRIPT_2018 feature "RegExp Lookbehind" to targeted output language.

thheller14:11:22

don't have it transpile to such a low language lvl

thheller14:11:59

:language-out :es2020 for figwheel build options

cjohansen14:11:46

Thanks 🙏 I was looking at the wrong options 🙂

thheller14:11:15

looks to be missing some newer options yes

cjohansen14:11:33

Perfect, thanks 🙂

dnolen15:11:07

Updated the site

👍 1
cjohansen16:11:45

Turns out figwheel-main has some out of date validation for this option, I'll submit a fix