Created
March 7, 2014 14:42
-
-
Save timwingfield/9412684 to your computer and use it in GitHub Desktop.
testing a jquery selector value
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 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