-
-
Save athomasoriginal/72119cf7fad645c4844bae866863d2b9 to your computer and use it in GitHub Desktop.
Example cljs test helpers
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
;; ----------------------------------------------------------------------------- | |
;; app.debug_tools.cljs | |
;; ----------------------------------------------------------------------------- | |
(ns app.debug-tools | |
(defmacro with-fake-log | |
"Stub console.log to prevent console noise. console.logs will be saved to the | |
atom provided as the first argument" | |
[fake-log & body] | |
`(let [original-log# js/console.log | |
new-log# (fn [n#] (reset! ~fake-log n#))] | |
(set! js/console.log new-log#) | |
~@body | |
(set! js/console.log original-log#))) | |
(defmacro p | |
"Print and return native JavaScript argument." | |
[x] | |
`(let [res# ~x] | |
(.log js/console res#) | |
res#)) | |
;; ----------------------------------------------------------------------------- | |
;; app.debug_tools_test.cljs | |
;; ----------------------------------------------------------------------------- | |
(ns app.debug-tools-test | |
(:require | |
[cljs.test :refer-macros [deftest is]]) | |
(:require-macros | |
[app.debug-tools-test :refer [p with-fake-log]])) | |
(def fake-log (atom nil)) | |
(deftest debugging-tools | |
(with-fake-log | |
fake-log | |
(is (= "my name is what?" (p "my name is what?"))) | |
(is (= "my name is what?" @fake-log)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment