Fork me on GitHub

with Clojurescript’s async test macro, how do I test that a promise is rejected?


found an example in promesas docs

(t/deftest promise-from-exception
       (let [e (ex-info "foo" {})
             p1 (p/promise e)]
         (t/is (p/rejected? p1))
         (t/is (= e @@(p/catch p1 (fn [x] (reduced x))))))
       (t/async done
         (let [e (ex-info "foo" {})
               p1 (p/promise e)]
           ;; (t/is (p/rejected? p1))
           (p/catch p1 (fn [x]
                         (t/is (= e x))

paul a20:02:01

i'm trying to write tests for some browser-targeted CLJS code. the code i'd like to test operates on a 2MB file; that's too much to inline somewhere, so i'd like to read that data from a file in my project dir and use it in my CLJS test.

paul a20:02:27

i sort of understand that i'm barking up the wrong tree trying to read in a file from disk in browser-targeted CLJS, because the browser has no such capabilities.

paul a20:02:08

i've seen examples where people use clojure's slurp at compile time, but i haven't been able to get any of those examples working for myself.

paul a20:02:48

i'd also really like to avoid serving the file from a local HTTP server; that seems ridiculously heavy for this purpose, and i would love for there to be some simpler solution.

paul a20:02:36

if anyone here has thoughts on this, i'd love to hear them.


If that's just for tests, then it should be perfectly fine to inline the data. All the examples that slurp the data during compile time do exactly that. This is relevant, if you use shadow-cljs:

paul a20:02:38

oh yeah, that's perfect. thanks!