Skip to content

Instantly share code, notes, and snippets.

@ralfschimmel
Created February 23, 2012 20:33
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 ralfschimmel/1894905 to your computer and use it in GitHub Desktop.
Save ralfschimmel/1894905 to your computer and use it in GitHub Desktop.
ember-skeleton QUnit
#Add this to you asset file
match 'tests/**/*.js' do
filter LoaderFilter,
:module_id_generator => proc { |input|
input.path.sub(/^lib\//, "#{APPNAME}/").sub(/\.js$/, '')
}
concat 'yourlib-tests.js'
end
<!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>
</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>
<script>
// Load custom version of jQuery if possible
var jQueryMatch = location.search.match(/jquery=([^&]+)/),
jQueryVersion = jQueryMatch ? jQueryMatch[1] : "1.7.1";
if (jQueryVersion !== 'none') {
document.write(unescape('%3Cscript src="//ajax.googleapis.com/ajax/libs/jquery/'+jQueryVersion+'/jquery.js"%3E%3C/script%3E'));
}
// Close the script tag to make sure document.write happens
</script>
<script>
// Fallback to default jQuery
if (jQueryVersion !== 'none' && !window.jQuery) {
if (console && console.warn) { console.warn("Unable to load jQuery "+jQueryVersion+". Using default."); }
document.write(unescape('%3Cscript src="jquery-1.7.1.js"%3E%3C/script%3E'));
}
</script>
<script type="text/javascript" src="../assets/loader.js"></script>
<script type="text/javascript" src="../vendor/ember-0.9.5.js"></script>
<script type="text/javascript" src="../assets/yourlib.js"></script>
<script type="text/javascript" src="../assets/yourlib-tests.js"></script>
<script type="text/javascript">
// Handle extending prototypes
QUnit.config.urlConfig.push('extendprototypes');
window.ENV = window.ENV || {};
var extendPrototypes = location.search.match(/extendprototypes=([^&]+)/);
ENV['EXTEND_PROTOTYPES'] = !!(extendPrototypes && decodeURIComponent(extendPrototypes[1]));
// hack qunit to not suck for Ember objects
var originalTypeof = QUnit.jsDump.typeOf;
QUnit.jsDump.typeOf = function(obj) {
if (Ember && Ember.Object && Ember.Object.detectInstance(obj)) {
return "emberObject";
}
return originalTypeof.call(this, obj);
};
QUnit.jsDump.parsers.emberObject = function(obj) {
return obj.toString();
}
re = new RegExp('^tests/');
for (moduleName in loader.modules) {
match = moduleName.match(re);
if (match) {
loader.require(moduleName);
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment