Skip to content

Instantly share code, notes, and snippets.

@searls
Created May 19, 2011 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save searls/980580 to your computer and use it in GitHub Desktop.
Save searls/980580 to your computer and use it in GitHub Desktop.
Add a little spy on creator that defaults to return this to support jQuery-like chaining.
buttonifyAndHide = function($obj) {
$obj.button().hide();
};
var $thing;
beforeEach(function(){
spyOnAndChain($.fn,'button');
$thing = $.jasmine.inject('<div></div>'); //See: https://github.com/searls/jasmine-fixture
buttonifyAndHide($thing);
});
it('calls button',function(){
expect($.fn.button).toHaveBeenCalled();
});
it('is hidden',function(){
expect($thing).not.toBeVisible();
});
(function(){
window.spyOnAndChain = function(obj,method){
spyOn(obj,method).andCallFake(function(){
return this;
});
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment