Created
July 26, 2011 15:18
-
-
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.
This file contains 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
// 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'); | |
}); | |
}); | |
}); |
This file contains 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
(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); |
This file contains 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
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