devcards

Devcards aims to provide a visual REPL experience for ClojureScript https://github.com/bhauman/devcards
adamfrey 2019-03-28T21:18:29.002Z

Is there a way to mock out functions used by components being rendered in a devcard? For instance if I have this component:

(ns scratch-reagent-devcards.components)

(defn click-handler []
  (prn "real handler"))

(defn first-component []
  [:button {:on-click click-handler} "Click Me"])
is there a way to render that reagent component in a devcard but swap out the click-handler for something else?
(defcard-rg first-card
  (with-redefs [comp/click-handler #(prn "mocked handler")]
    [comp/first-component]))
doesn't work.

metametadata 2019-03-28T21:46:42.004100Z

It's expected because by the time user clicks a button with-redefs block is finished. Instead make click-handler an explicit parameter of first-component.