Skip to content

Instantly share code, notes, and snippets.

@davemo
Created July 26, 2011 15:18
Show Gist options
  • Save davemo/1106994 to your computer and use it in GitHub Desktop.
Save davemo/1106994 to your computer and use it in GitHub Desktop.
A jasmine matcher to assert the value of the 'selector' in a jQuery selection.
// An App module to control feature parity amongst browsers that don't support them, HTML5 placeholder in this case.
describe("APP.Degrade", function() {
describe('#shimPlaceholders', function() {
it('invokes the html5 placeholder plugin on all input and textareas', function() {
spyOn($.fn, 'placeholder');
APP.Degrade.shimPlaceholders();
expect($.fn.placeholder).toHaveBeenInvokedOnSelector('input, textarea');
});
});
});
(function($, APP) {
APP.Degrade = {};
// the function we want under test.
APP.Degrade.shimPlaceholders = function() {
$('input, textarea').placeholder(); // dependency: https://github.com/mathiasbynens/Placeholder-jQuery-Plugin
};
APP.Degrade.shimPlaceholders();
})(jQuery, APP);
beforeEach(function() {
this.addMatchers({
// yay for custom matchers!
toHaveBeenInvokedOnSelector: function(expected) {
return this.actual.mostRecentCall.object.selector === expected;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment