Created
October 14, 2011 12:35
-
-
Save odyssomay/1286986 to your computer and use it in GitHub Desktop.
Clojurescript testing using jasmine
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 a) | |
(defn add-one [x] (+ x 1)) |
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 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))) |
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 jsm) | |
(def describe* (js* "describe")) | |
(def it* (js* "it")) | |
(def expect* (js* "expect")) |
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 jsm-m) | |
(defmacro describe [description & body] | |
`(~'describe* ~description (fn [] ~@body))) | |
(defmacro it [description test-form] | |
`(~'it* ~description | |
(fn [] | |
(. (~'expect* ~test-form) (~'toBeTruthy))))) |
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
<!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> |
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
Sorry! I somehow didn't get any notification for your comment, or missed it.
I hope this late response haven't delayed your project!
In any case, you can link to this page, or write my name somewhere where it's appropriate (for example in the beginning of these files).
You can also chose not to give credit at all, I'm fine with that. :)