public
Created — forked from searls/some-source.js

Add a little spy on creator that defaults to return this to support jQuery-like chaining.

  • Download Gist
some-source.js
JavaScript
1 2 3
buttonifyAndHide = function($obj) {
$obj.button().hide();
};
some-spec.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
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();
});
spec-helper.snippet.js
JavaScript
1 2 3 4 5 6 7 8
 
(function(){
window.spyOnAndChain = function(obj,method){
spyOn(obj,method).andCallFake(function(){
return this;
});
};
})();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.