This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-09
Channels
- # announcements (16)
- # babashka (28)
- # beginners (27)
- # calva (39)
- # chlorine-clover (6)
- # cider (8)
- # clara (28)
- # cljs-dev (19)
- # cljsrn (22)
- # clojure (78)
- # clojure-australia (3)
- # clojure-europe (64)
- # clojure-nl (3)
- # clojure-norway (14)
- # clojure-spec (2)
- # clojure-uk (11)
- # clojurescript (11)
- # core-async (24)
- # datomic (3)
- # deps-new (5)
- # emacs (9)
- # fulcro (4)
- # gis (2)
- # graalvm (9)
- # honeysql (2)
- # hoplon (5)
- # instaparse (1)
- # introduce-yourself (5)
- # jobs (5)
- # luminus (4)
- # observability (7)
- # off-topic (6)
- # pathom (18)
- # pedestal (5)
- # polylith (4)
- # re-frame (2)
- # reagent (1)
- # reitit (1)
- # remote-jobs (7)
- # shadow-cljs (47)
- # specter (1)
- # sql (27)
- # testing (6)
- # tools-deps (4)
- # vim (3)
- # xtdb (8)
I am trying to mock UUID generation for a test case with with-redefs
. It works as long as I call my function directly, but it stops working as soon as I map my function over some data.
I created a very small example that shows my problem here:
https://replit.com/@JacobEmcken/LovingGorgeousAfkgaming
I don't understand why map
makes a difference nor how I should mock my id generation if this doesn't work 😕
Does anyone have an idea?
user=> (with-redefs [uuid (uuid-mock)] (mapv geif-ids '(1 2)))
[("UUID-1") ("UUID-2" "UUID-3")]
using mapv
(or (into [] ...
or doall
will realize the whole list at the time it’s called instead of when it’s printed to the console or used in some calculation
user=> (with-redefs [uuid (uuid-mock)] (map geif-ids '(1 2)))
(("a52c1525-63ed-46c1-8070-5b27d193f2ce") ("4ce9d4e8-ff19-4947-8f7f-fa20d1b47ad9" "47727d0c-c222-4992-846b-6e4b93cffb83"))
user=> (with-redefs [uuid (uuid-mock)] (mapv geif-ids '(1 2)))
[("UUID-1") ("UUID-2" "UUID-3")]
user=> (with-redefs [uuid (uuid-mock)] (doall (map geif-ids '(1 2))))
(("UUID-1") ("UUID-2" "UUID-3"))
user=> (with-redefs [uuid (uuid-mock)] (into [] (map geif-ids '(1 2))))
[("UUID-1") ("UUID-2" "UUID-3")]
ahh that makes sense. Thanks a lot :thumbsup: