Created
June 21, 2012 17:51
-
-
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
This file contains hidden or 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
// The production code in question, part of a backbone view | |
showSearch: function () { | |
this.$('.dataTables_filter').show(); | |
} |
This file contains hidden or 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
// 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