Skip to content

Instantly share code, notes, and snippets.

Created May 28, 2012 15:12
Show Gist options
  • Save oslego/2819653 to your computer and use it in GitHub Desktop.
Save oslego/2819653 to your computer and use it in GitHub Desktop.
QUnit and Browserscope boilerplate code.
<!DOCTYPE html>
<link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="qunit/jquery.js"></script>
<script type="text/javascript" src="qunit/qunit.js"></script>
<script type="text/javascript">
// To save data in Browserscope do something like the following.
// The syntax is 'test_key': 'value' where test_key is some unique
// identifier for a piece of data you want to store (no = or , allowed)
// and value is a numeric value from 0 through 1000000000000.
// Note: You can only send a maximum of 200 results in a beacon.
var _bTestResults = {}
// Add URL option in QUnit to toggle publishing results to
// Timeout for async tests
QUnit.config.testTimeout = 1000
// Build-up the test results beacon for
QUnit.testDone = function(test){
// make sure all assertions passed successfully
if (!test.failed && === test.passed){
_bTestResults[] = 1
_bTestResults[] = 0
// If the user agreed to publish results to, go for it!
QUnit.done = function(){
if (QUnit.config.publishresults){
newScript = document.createElement('script'),
firstScript = document.getElementsByTagName('script')[0]
newScript.src = '' + testKey + "?callback=showResults"
firstScript.parentNode.insertBefore(newScript, firstScript)
// Load the results widget from
function showResults(){
var script = document.createElement('script')
script.src = ""
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment