Fork me on GitHub
#clojurescript
<
2021-11-20
>
Oliver George05:11:41

Can someone please point me at code using tc/quick-check inside deftest. I'm looking for a clean way to wire things up and get nice error reports.

Oliver George09:11:15

One simple pattern is

(deftest t1
  (is (:result (tc/quick-check 100 t1-prop))))
No nice debugging info in report but does at least tell you where it hurts.

West16:11:01

defspec is a macro with the same behavior as quick-check and it integrates with clojure.test. Check it: https://github.com/clojure/test.check/blob/master/doc/intro.md#clojuretest-integration

Oliver George00:11:04

Thanks @U01KQ9EGU79 - I hit some odd things with the shadow-cljs repl but perhaps that's surmountable. Looks spot on.

Oliver George00:11:16

Also, this helper/pattern gives me reasonable debugging info without too much plumbing. (Can't recall where I found it.)

(defn qc-ret
  [{:keys [result] :as data}]
  (if result {:result true} data))

(deftest init-db--gen
  (is (= {:result true} (qc-ret (tc/quick-check 100 init-db--fx-ret)))))

dpsutton06:11:59

I don't have examples handy but the first place I would look is http://grep.app

Oliver George07:11:12

Fancy! Thanks.

Karl Xaver11:11:38

Newbie question: How do you experiment with/inspect objects like #object[HTMLImageElement [object HTMLImageElement]] #object[CSSStyleDeclaration [object CSSStyleDeclaration]] js->clj doesn't seem to do anything on these. So far I resorted to (js/console.log object) + scrolling/clicking through the browsers console which is a bit tedious. Thanks!

p-himik11:11:12

If the browser console is tedious while being as interactive as it is (you can run arbitrary JS code on those objects or their subfields), what kind of workflow would be better?

Schpaa11:11:10

if you prefix your log-output with a string-token you can use the console´s filtering facilities to include this token and remove all the noise.

p-himik11:11:05

Browsers' JS consoles have many tools nowadays. Filtering, grouping, pivoting, evaluation, saving nested objects via context menus, probably other things that I can't recall right now or simply don't know about.

Karl Xaver12:11:44

"Tedious" was a bit of an overstatement :) I just thought there might be something I missed that's more integrated with the repl/editor, so I don't have to 1) wrap my obj in a console.log expr (compared to evaling directly) 2) switch to the browser 3) use the mouse to find/unfold things It's time to give the console some love and learn its keyboard shortcuts. I wasn't aware that it is so powerful. And 1) can be solved with some elisp. Using the string-token tip already. Thanks for the input!

p-himik12:11:14

There are also things like https://github.com/djblue/portal but I have no idea how good they are with JS objects. But if you work with CLJ/Java data that you want to inspect, those are great tools.

eyalch17:11:50

Anybody using the Cursive plugin and is able to have symbols like .getElementById resolved?

p-himik17:11:35

It's an old and known problem: https://github.com/cursive-ide/cursive/issues/1252 There's also #cursive

eyalch18:11:45

Bummer, oh well