Fork me on GitHub
#testing
<
2020-11-30
>
jaime21:11:09

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?