Skip to content

Instantly share code, notes, and snippets.

@roman
Created November 23, 2012 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roman/4137377 to your computer and use it in GitHub Desktop.
Save roman/4137377 to your computer and use it in GitHub Desktop.
help with macros in cljs
(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"))))))
(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)))))))
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