Created
May 26, 2012 18:28
-
-
Save commadelimited/2794863 to your computer and use it in GitHub Desktop.
unit testing
This file contains hidden or 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
/* | |
* jquery.grunt-test | |
* https://github.com/andymatthews/jquery.grunt-test | |
* | |
* Copyright (c) 2012 andy matthews | |
* Licensed under the MIT, GPL licenses. | |
*/ | |
(function($) { | |
// Collection method. | |
$.fn.awesome = function() { | |
}; | |
}(jQuery)); |
This file contains hidden or 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
/* | |
* jquery.grunt-test | |
* https://github.com/andymatthews/jquery.grunt-test | |
* | |
* Copyright (c) 2012 andy matthews | |
* Licensed under the MIT, GPL licenses. | |
*/ | |
(function($) { | |
// Collection method. | |
$.fn.awesome = function() { | |
return this.each(function() { | |
$(this).html('awesome'); | |
}); | |
}; | |
// Static method. | |
$.awesome = function() { | |
return 'awesome'; | |
}; | |
// Custom selector. | |
$.expr[':'].awesome = function(elem) { | |
return elem.textContent.indexOf('awesome') >= 0; | |
}; | |
}(jQuery)); |
This file contains hidden or 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
/*global QUnit:false, module:false, test:false, asyncTest:false, expect:false*/ | |
/*global start:false, stop:false ok:false, equal:false, notEqual:false, deepEqual:false*/ | |
/*global notDeepEqual:false, strictEqual:false, notStrictEqual:false, raises:false*/ | |
(function($) { | |
test("chainable", function() { | |
ok($("p b").awesome().addClass("testing"), "can be chained"); | |
equal($("p b").hasClass("testing"), true, "class was added correctly from chaining"); | |
}); | |
}(jQuery)); |
This file contains hidden or 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>jQuery Grunt Test Test Suite</title> | |
<!-- Load local jQuery, removing access to $ (use jQuery, not $). --> | |
<script src="../libs/jquery/jquery.js"></script> | |
<script>jQuery.noConflict()</script> | |
<!-- Load local QUnit (grunt requires v1.0.0 or newer). --> | |
<link rel="stylesheet" href="../libs/qunit/qunit.css" media="screen"> | |
<script src="../libs/qunit/qunit.js"></script> | |
<!-- Load local lib and tests. --> | |
<script src="../src/jquery.grunt-test.js"></script> | |
<script src="jquery.grunt-test_test.js"></script> | |
</head> | |
<body> | |
<h1 id="qunit-header">jQuery Grunt Test 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"> | |
<p> | |
3 wolf moon keytar mixtape seitan whatever,fixie <b>retro</b> readymade irony four loko blog. mcsweeney's skateboard VHS hoodie tumblr master cleanse vice organic keffiyeh. Scenester echo park banksy. Scenester 8-bit mustache, lo-fi mlkshk wolf <b>readymade</b> tumblr craft beer cosby sweater fap artisan fixie. | |
</p> | |
</div> | |
</body> | |
</html> |
This file contains hidden or 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
/*global QUnit:false, module:false, test:false, asyncTest:false, expect:false*/ | |
/*global start:false, stop:false ok:false, equal:false, notEqual:false, deepEqual:false*/ | |
/*global notDeepEqual:false, strictEqual:false, notStrictEqual:false, raises:false*/ | |
(function($) { | |
module('jQuery#awesome', { | |
setup: function() { | |
this.elems = $('#qunit-fixture').children(); | |
} | |
}); | |
test('is chainable', 1, function() { | |
// Not a bad test to run on collection methods. | |
strictEqual(this.elems.awesome(), this.elems, 'should be chaninable'); | |
}); | |
test('is awesome', 1, function() { | |
strictEqual(this.elems.awesome().text(), 'awesomeawesomeawesome', 'should be thoroughly awesome'); | |
}); | |
module('jQuery.awesome'); | |
test('is awesome', 1, function() { | |
strictEqual($.awesome(), 'awesome', 'should be thoroughly awesome'); | |
}); | |
module(':awesome selector', { | |
setup: function() { | |
this.elems = $('#qunit-fixture').children(); | |
} | |
}); | |
test('is awesome', 1, function() { | |
// Use deepEqual & .get() when comparing jQuery objects. | |
deepEqual(this.elems.filter(':awesome').get(), this.elems.last().get(), 'knows awesome when it sees it'); | |
}); | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment