Skip to content

Instantly share code, notes, and snippets.

@odyssomay
Created October 14, 2011 12:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odyssomay/1286986 to your computer and use it in GitHub Desktop.
Save odyssomay/1286986 to your computer and use it in GitHub Desktop.
Clojurescript testing using jasmine
(ns a)
(defn add-one [x] (+ x 1))
(ns a_test
(:use [jsm :only [describe* it* expect*]]
[a :only [add-one]])
(:require-macros [jsm-m :as j]))
(j/describe "testing the tests"
(j/it "should be equal"
(= 1 1)))
(j/describe "add-one"
(j/it "should add one"
(= (add-one 1) 2))
(j/it "should always add one"
(= (add-one 2) 3)))
(ns jsm)
(def describe* (js* "describe"))
(def it* (js* "it"))
(def expect* (js* "expect"))
(ns jsm-m)
(defmacro describe [description & body]
`(~'describe* ~description (fn [] ~@body)))
(defmacro it [description test-form]
`(~'it* ~description
(fn []
(. (~'expect* ~test-form) (~'toBeTruthy)))))
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="shortcut icon" type="image/png" href="jasmine/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="jasmine/jasmine.css">
<script type="text/javascript" src="jasmine/jasmine.js"></script>
<script type="text/javascript" src="jasmine/jasmine-html.js"></script>
<script type="text/javascript" src="out/goog/base.js"></script>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript" src="core.js"></script>
<script type="text/javascript">
goog.require('a_test')
</script>
<script type="text/javascript">
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var trivialReporter = new jasmine.TrivialReporter();
jasmineEnv.addReporter(trivialReporter);
jasmineEnv.specFilter = function(spec) {
return trivialReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
})();
</script>
</head>
<body>
</body>
</html>
@odyssomay
Copy link
Author

Also, I think the lines

(def describe* (js* "describe"))
(def it* (js* "it"))
(def expect* (js* "expect"))

should be changed to

(def describe* js/describe)
(def it* js/it)
(def expect* js/expect)

since the js* macro is not really idiomatic, and might even be removed from future clojurescript.
(note that I haven't actually tested the above)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment