Skip to content

Instantly share code, notes, and snippets.

@davemo
Created June 21, 2012 17:51
Show Gist options
  • Save davemo/2967335 to your computer and use it in GitHub Desktop.
Save davemo/2967335 to your computer and use it in GitHub Desktop.
A way to spy on and verify the selector when using this.$(selector) with a Backbone.View
// The production code in question, part of a backbone view
showSearch: function () {
this.$('.dataTables_filter').show();
}
// We have a view with a function that binds an event to a button that shows a search box
describe('showSearch', function () {
var showSpy;
beforeEach(function () {
showSpy = jasmine.createSpy('showSpy');
spyOn(view, '$').andReturn({ show: showSpy });
view.showSearch();
});
it('should trigger show on its search filters', function () {
expect(view.$).toHaveBeenCalledWith('.dataTables_filter');
expect(showSpy).toHaveBeenCalled();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment