Created
July 29, 2011 04:51
-
-
Save elithompson/1113154 to your computer and use it in GitHub Desktop.
Unit testing CoffeeScript with QUnit
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
class Dog | |
speak: -> "woof" | |
legs: 4 |
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
module "Dog" | |
test "dog says woof", 1, () -> | |
dog = new Dog() | |
actual = dog.speak() | |
equal actual, "woof" | |
test "dogs have four legs", 1, () -> | |
dog = new Dog() | |
actual = dog.legs | |
equal actual, 4 |
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> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>QUnit Test Suite</title> | |
<link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen"> | |
<script type="text/javascript" src="qunit/qunit.js"></script> | |
<script type="text/javascript" src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> | |
<script type="text/coffeescript"> | |
$ -> | |
scriptsToTest = ["dog.coffee"] | |
tests = ["dog.test.coffee"] | |
loadCoffee = (files) -> | |
$head = $ "head" | |
load = (file) -> | |
$.get file, (content) -> | |
compiled = CoffeeScript.compile content, {bare: on} | |
$("<script />").attr("type", "text/javascript").html(compiled).appendTo $head | |
load file for file in files | |
loadCoffee scriptsToTest | |
loadCoffee tests | |
</script> | |
</head> | |
<body> | |
<h1 id="qunit-header">QUnit Test Suite</h1> | |
<h2 id="qunit-banner"></h2> | |
<div id="qunit-testrunner-toolbar"></div> | |
<h2 id="qunit-userAgent"></h2> | |
<ol id="qunit-tests"></ol> | |
<div id="qunit-fixture">test markup</div> | |
</body> | |
</html> |
@AngeliqueVille - I did it not three weeks ago, and it works fine for me. See my blog post (linked from an earlier comment) on how I did it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@AngeliqueVille Can't help you there. I haven't tried working on this in a while so you're on your own.