Fork me on GitHub

I'm trying to test for a list in a unit test. The tested function returns a list but when writing the test I have issues with quoting the list. When the test is executed doing '("testdata") results in (quote ("testdata")) which is not equal to ("testdata"). Maybe I should read up on quoting?


I've also tried (list ("testdata")) but that doesn't work either. Funny enough, though, it did work in another test. 😕


(quote ("testdata")) should not be a problem:

=> (= (quote (a)) (list 'a))
It sounds like you're comparing not the data itself but the forms. Are you sure you need to compare forms?


Thanks a lot for this hint. Something else in my test data wasn't right. I was just distracted by the fact that the output printed (quote (a)). 😄


Also, I probably need to cut my tests into smaller pieces. If I had done that right away, I would have noticed the issue without any help.


just use (list "testdata") and don't worry about quoting 😉

🙂 1
Jacob Emcken18:01:25

I am using " duration objects" in my ClojureScript frontend and I would like to transfer them to Clojure backend using Transit. I'm supposed to give the Transit "write handler" a type... how do I figure out which type Day.js durantion objects are. Running (type duration-object) returns #object[l], but I cannot see where I go from there. This is what I've got:

(def write-handlers
  {???? (transit/write-handler "time/duration"
   ^^^^                        (fn [duration]
   What "type" goes here?        (.toISOString duration)))})


I would try creating a dummy duration and putting (type dummy-duration) in there.


AFAICT, Day.js does not export the Duration class itself so there's no way to get it in an explicit way via an import.

Jacob Emcken18:01:51

ahhh :thinking_face: I know what to test next... I'm going to get something to eat first 😁

Jacob Emcken18:01:09

but makes sense (now that I think about it)

Jacob Emcken18:01:51

It worked... thank you ❤️

👍 1
Jacob Emcken18:01:57

For anyone who might find themselves in the same bind as me:

(ns app.transit-format
  (:require ["dayjs" :as dayjs]
            ["dayjs/plugin/duration" :as duration]
            [cognitect.transit :as transit]))

;; Extend Day.js with more functionality
(.extend dayjs duration)

(def duration-type
  (type (dayjs/duration 1)))

(def write-handlers
  {duration-type (transit/write-handler "time/duration"
                                        (fn [duration]
                                          (.toISOString duration)))})

(def read-handlers
  {"time/duration" (transit/read-handler #(dayjs/duration %))})

(def custom
  "Read and write data encoded in transit+json."
  (reify fmt/Format
    (read  [_ s] (transit/read (transit/reader :json {:handlers read-handlers}) s))
    (write [_ v] (transit/write (transit/writer :json {:handlers write-handlers}) v))))

Jacob Emcken18:01:26

ups... was supposed to have been in "thread", sorry 😄


It would also probably be better as a Gist - much easier to find and share when you're outside of Slack.