Skip to content

Instantly share code, notes, and snippets.

@vojtajina
Created February 21, 2014 01:52
Show Gist options
  • Save vojtajina/9127352 to your computer and use it in GitHub Desktop.
Save vojtajina/9127352 to your computer and use it in GitHub Desktop.
Code example for Merrick.
it('should call append', inject($, MyUI, function(jQuery, ui) {
spyOn(jQuery, 'append');
ui.render();
expect(jQuery.append).toHaveBeenCalled();
});
@Provide($)
function jQueryMock() {
$.cleanAllState();
spyOn($, 'append');
spyOn($, 'html');
return $;
}
beforeEach(use(jQueryMock));
it('should use mock', inject($, MyUI, function(jQuery, ui) {
ui.render();
expect(jQuery.append).toHaveBeenCalled();
});
it('should mock append before instantiating', function() {
inject($, function(jQuery) {
spyOn(jQuery, 'append');
});
inject($, MyUI, function(jQuery, ui) {
ui.render();
expect(jQuery.append).toHaveBeenCalled();
});
});
@iammerrick
Copy link

Thank you for this gist. Very helpful. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment