Skip to content

Instantly share code, notes, and snippets.

@apeckham
Created November 25, 2022 22:25
Show Gist options
  • Save apeckham/fb3ff26c05070d866263ed6cb4ca3f48 to your computer and use it in GitHub Desktop.
Save apeckham/fb3ff26c05070d866263ed6cb4ca3f48 to your computer and use it in GitHub Desktop.
picomock - for clojure mocks
(ns util.picomock-test
"https://github.com/audiogum/picomock"
(:require
[clojure.test :refer [deftest is testing]]
[picomock.core :as pico]))
(deftest picomock-test
(testing "without a function"
(let [mock (pico/mock)]
(is (nil? (mock)))
(is (= 1 (pico/mock-calls mock)))))
(testing "with one function"
(let [mock (pico/mock (fn [a b] (+ a b)))]
(is (= 3 (mock 1 2)))
(is (= 5 (mock 3 2)))
(is (= 2 (pico/mock-calls mock)))
(is (= [[1 2] [3 2]] (pico/mock-args mock)))))
(testing "with multiple functions"
(let [mock (pico/mock [(constantly 1) (constantly 2)])] ;
(is (= [1 2 1 2] [(mock) (mock) (mock) (mock)])))))
(deftest mockval-test (let [mock (pico/mockval 5)] (is (= [5 5 5] [(mock) (mock) (mock)]))))
(deftest mockvals-test (let [mock (pico/mockvals [1 2 3])] (is (= [1 2 3 1] [(mock) (mock) (mock) (mock)]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment