Skip to content

Instantly share code, notes, and snippets.

@searls
Created February 8, 2011 14:24
Show Gist options
  • Save searls/816504 to your computer and use it in GitHub Desktop.
Save searls/816504 to your computer and use it in GitHub Desktop.
testing your jQuery binding in jasmine
(function($){
me = me || {};
$.extend(me,{
bind: function(){
$('body').delegate('a.modal','click',me.openModal)
},
openModal: function(){
var $link = $(this);
//...
}
});
})(jQuery);
jQuery(function($){
me.bind();
});
////////////////
//requires https://github.com/searls/jasmine-fixture
describe('Me',function(){
describe('#bind',function(){
describe('clicking a modal link',function(){
var $link;
beforeEach(function(){
$link = $.jasmine.inject('<a class="modal"></a>');
spyOn(me,'openModal');
me.bind();
$link.click();
});
it('opens a modal',function(){
expect(me.openModal).toHaveBeenCalled();
});
});
});
describe('#openModal',function(){
var $link;
beforeEach(function(){
$link = $.jasmine.inject('<a></a>');
me.openModal.call($link[0]);
});
it('...does stuff...?');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment