Skip to content

Instantly share code, notes, and snippets.

@mlewand
Created February 6, 2015 15:14
Show Gist options
  • Save mlewand/73d2cd4f767d4946c088 to your computer and use it in GitHub Desktop.
Save mlewand/73d2cd4f767d4946c088 to your computer and use it in GitHub Desktop.
Quail should call `testCollectionComplete` after a brief timeout, causing an alert.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>title</title>
</head>
<body>
<div id="sampleContent">
<p>This element contains <b>bold</b>.</p>
</div>
<script src="lib/jquery/jquery.js"></script>
<script src="dist/quail.jquery.js"></script>
<script>
function testCollectionComplete( collection ) {
// Iterating over Test objects...
collection.each( function( testIndex, testInstance ) {
// Count of failed tested cases.
var actualFailedCases = 0,
// Expected failed cases count.
expectedFailedCases = 1;
// Iterating over each case...
testInstance.each( function( index, testCase ) {
if ( testCase.get( 'status' ) == 'failed' ) {
actualFailedCases += 1;
}
} );
// Lets check if the expected and actual cases count is the same.
if ( actualFailedCases === expectedFailedCases ) {
alert( 'OK' );
} else {
alert( 'Invalid len ' + actualFailedCases + ', expected: ' + expectedFailedCases );
}
} );
}
setTimeout( function() {
// Execute Quail checking after small timeout.
$( '#sampleContent' ).quail( {
guideline : [ 'boldIsNotUsed' ],
jsonPath: 'dist/',
testCollectionComplete: function ( eventName, testCollection ) {
testCollectionComplete( testCollection );
}
} );
}, 300 );
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment