Created
November 23, 2012 21:22
-
-
Save roman/4137377 to your computer and use it in GitHub Desktop.
help with macros in cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns buster-cljs.test.macros-test | |
(:require [buster-cljs.core :as core]) | |
(:require-macros [buster-cljs.macros | |
:refer [initialize-buster deftest describe it is]])) | |
(deftest is-macro-with-exception-features | |
(it "assertions with `thrown?'" | |
(is (thrown? js/Error | |
(throw (js/Error. "an error")))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns buster-cljs.macros | |
(:refer-clojure :exclude [try]) | |
(:require [cljs.core :refer [try]] | |
[clojure.string :as str])) | |
(defmethod assert-expr 'thrown-with-msg? [msg form] | |
;; we ignore on purpuse the exception argument | |
;; (it always going to be js/Error) | |
(let [re (nth form 2) | |
body (nthnext form 3)] | |
`(try | |
~@body | |
(.assert js/buster false "expected error to be thrown.") | |
(catch js/Error e | |
(.assert js/buster (re-find ~re (.-message e))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buster.spec.describe("is macro with exception features", function() { | |
buster.spec.it("assertions with `thrown?'", function() { | |
throw Error("an error"); | |
}); | |
return null | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment