Created
February 8, 2011 14:24
-
-
Save searls/816504 to your computer and use it in GitHub Desktop.
testing your jQuery binding in jasmine
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($){ | |
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