Fork me on GitHub
#clojurescript
<
2020-02-17
>
martinklepsch19:02:33

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

martinklepsch20:02:11

found an example in promesas docs

(t/deftest promise-from-exception
    #?(:clj
       (let [e (ex-info "foo" {})
             p1 (p/promise e)]
         (t/is (p/rejected? p1))
         (t/is (= e @@(p/catch p1 (fn [x] (reduced x))))))
       :cljs
       (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))
                         (done)))))))

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.

p-himik20:02:32

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: https://clojureverse.org/t/using-none-code-resources-in-cljs-builds/3745

paul a20:02:38

oh yeah, that's perfect. thanks!