|
13 | 13 |
|
14 | 14 | #?(:clj [clojure.test :refer [deftest is do-report testing]]
|
15 | 15 | :cljs [cljs.test :include-macros true
|
16 |
| - :refer [do-report assert-expr] |
| 16 | + :refer [do-report assert-expr] |
17 | 17 | :refer-macros [deftest is testing assert-expr
|
18 |
| - use-fixtures]]) |
| 18 | + use-fixtures]]) |
19 | 19 | #?(:cljs [cljs.spec.alpha :as s])
|
20 | 20 | #?(:cljs [expectations.clojure.test-spec])
|
21 | 21 | #?(:clj [expectations.clojure.test :refer
|
|
59 | 59 | ;; TODO: fails because regexes never compare equal to themselves!
|
60 | 60 | #_(is-not' (sut/expect #"fool" "It's foobar!") (not (re-find #"fool" "It's foobar!"))))
|
61 | 61 |
|
| 62 | +#?(:clj (def get-ex-message (or (resolve 'clojure.core/ex-message) |
| 63 | + (fn [^Throwable t] (.getMessage t)))) |
| 64 | + :cljs (def get-ex-message ex-message)) |
| 65 | + |
62 | 66 | #?(:clj (deftest exception-test
|
63 | 67 | (passes (sut/expect ArithmeticException (/ 12 0))
|
64 | 68 | (fn [ex]
|
65 | 69 | (let [t (Throwable->map ex)]
|
66 | 70 | (and (= "Divide by zero" (-> t :cause))
|
67 | 71 | (or (= 'java.lang.ArithmeticException (-> t :via first :type))
|
68 |
| - (= java.lang.ArithmeticException (-> t :via first :type)))))))) |
| 72 | + (= java.lang.ArithmeticException (-> t :via first :type))))))) |
| 73 | + (passes (sut/expect Exception (/ 12 0)) |
| 74 | + (fn [ex] |
| 75 | + (let [t (Throwable->map ex)] |
| 76 | + (and (= "Divide by zero" (-> t :cause)) |
| 77 | + (or (= 'java.lang.ArithmeticException (-> t :via first :type)) |
| 78 | + (= java.lang.ArithmeticException (-> t :via first :type))))))) |
| 79 | + (is (sut/expect (more-> ArithmeticException type #"Divide by zero" get-ex-message) (/ 12 0))) |
| 80 | + (is (sut/expect (more-> Exception type #"Divide by zero" get-ex-message) (/ 12 0)))) |
69 | 81 |
|
70 | 82 | :cljs (deftest cljs-exception-test
|
71 | 83 | (passes (sut/expect js/Error (throw (ex-info "foo" {})))
|
|
0 commit comments