This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-30
Channels
- # adventofcode (4)
- # aleph (1)
- # announcements (7)
- # aws (10)
- # babashka (23)
- # beginners (23)
- # calva (20)
- # chlorine-clover (13)
- # cider (17)
- # clj-kondo (13)
- # cljfx (9)
- # cljsrn (9)
- # clojure (98)
- # clojure-australia (1)
- # clojure-dev (15)
- # clojure-europe (127)
- # clojure-nl (4)
- # clojure-sanfrancisco (3)
- # clojure-uk (98)
- # clojurescript (25)
- # community-development (8)
- # core-async (15)
- # cryogen (9)
- # cursive (7)
- # data-science (1)
- # datascript (5)
- # datomic (3)
- # devcards (2)
- # fulcro (5)
- # graalvm (1)
- # helix (8)
- # jackdaw (1)
- # jobs (5)
- # kaocha (17)
- # malli (5)
- # meander (5)
- # off-topic (37)
- # pathom (33)
- # pedestal (3)
- # re-frame (12)
- # reitit (1)
- # remote-jobs (3)
- # sci (1)
- # shadow-cljs (6)
- # testing (1)
- # vim (6)
- # vrac (5)
Hi, what do you use to mock/spy function calls during testing?
I have the below test, and notice the on-change
which is kind of a mock with assertion that the value it receives is equal to some value.
I think the intent or the assertion there is not very clear to the reader. IMO, assertions should come at the end of the test
(deftest text-field
(testing "calls on-change with new value"
(let [new-value "jaime"
on-change #(is (= % new-value))] ;; I feel like the assertion inside the on-change is not very clear for the reader
(with-mounted-component
[ui/text-field {:id "text-input" :on-change on-change :label "foo"}]
(fn [{:keys [getByTestId]}]
(.change rtl/fireEvent (getByTestId "text-input") (clj->js {:target {:value new-value}}))
;; I think its better to have assertion here like (is-mock-called-with? on-change "jaime")))))
I'm thinking to try this one https://github.com/alexanderjamesking/spy , do you have other recommendations that I can try later?