Skip to content

Instantly share code, notes, and snippets.

@timwingfield
Created March 7, 2014 14:42
Show Gist options
  • Save timwingfield/9412684 to your computer and use it in GitHub Desktop.
Save timwingfield/9412684 to your computer and use it in GitHub Desktop.
testing a jquery selector value
//The method under test
on: function(event, fn){
$("#" + this.currentView.modalId).on(event, fn);
}
//The Jasmine spec
describe("account/company", function() {
Given(function() { this.view = { modalId: "modalId" } });
Given(function() { subject = new PopupView(this.view) });
describe("#on", function() {
Given(function() { this.event = "a major event" });
Given(function() { this.fn = function(){ return "a very cool function"} });
Given(function() { this.onSpy = spyOn($.fn, 'on') });
When(function() { subject.on(this.event, this.fn) });
Then(function() { expect($.fn.on).toHaveBeenCalledWith(this.event, this.fn); });
Then(function() { expect(this.onSpy.mostRecentCall.object.selector).toEqual("#" + this.view.modalId); });
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment