Skip to content

Instantly share code, notes, and snippets.

@JorgenHookham
Last active December 14, 2015 00:39
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 JorgenHookham/5001009 to your computer and use it in GitHub Desktop.
Save JorgenHookham/5001009 to your computer and use it in GitHub Desktop.
Boilerplate for widget unit tests
// Save these as two separate files.
// Write your tests in the js file.
// Run your tests from the html file.
// Add your test module to /static/lib/js/tests/run_all_js_tests.html
// lib/tests/unit_tests.js
define([
'jquery',
'underscore',
'backbone',
'../../review.js'
], function ($, _, Backbone, ReviewWidget) {
test('Universal truth test.', function () {
ok(1 == 1);
});
});
// lib/tests/test_loader.html
<!DOCTYPE html>
<html>
<head>
<title>JAVASCRIPT UNIT TEST</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css">
<script src="http://code.jquery.com/qunit/qunit-1.11.0.js"></script>
<script src="../../../../../lib/require/require.js"></script>
</head>
<body>
<div id="qunit"></div>
<script>
(function () {
QUnit.stop();
QUnit.config.autostart = false;
require.config({
baseUrl: './',
paths: {
main: '../../../../main',
lib: '../../../../../lib',
modules: '../../../../modules',
jquery: '../../../../../lib/jquery/jquery-min',
underscore: '../../../../../lib/underscore/underscore-amd-min',
backbone: '../../../../../lib/backbone/backbone-amd-min',
text: '../../../../../lib/require/text',
goog: '../../../../../lib/require/goog',
propertyParser : '../../../../../lib/require/propertyParser',
async: '../../../../../lib/require/async',
utils: '../../../../utils',
facebook_sdk: '../../../../facebook_sdk'
}
});
require(['tests'], QUnit.start());
}());
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment