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.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
.