Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Fix toHandleWith() #268

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/jasmine-jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
compare: function (actual, eventName, eventHandler) {
if ( !actual || actual.length === 0 ) return { pass: false };
var normalizedEventName = eventName.split('.')[0]
, stack = $._data($(actual).get(0), "events")[normalizedEventName]
, events = $._data($(actual).get(0), "events")
, stack

if (!events) return { pass: false };

stack = events[normalizedEventName]

if (!stack) return { pass: false };

for (var i = 0; i < stack.length; i++) {
if (stack[i].handler == eventHandler) return { pass: true }
Expand Down
17 changes: 11 additions & 6 deletions spec/suites/jasmine-jquery-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,10 @@ describe("jasmine.Fixtures using real AJAX call", function () {
expect($("#anchor_01").length).toBe(1)
})
})

describe("When the fixture contains a HTML 5 style checked checkbox", function () {
var fixtureUrl = "fixture_with_checkbox_with_checked.html"

it("Then the fixture is loaded successfully", function () {
jasmine.getFixtures().load(fixtureUrl)
expect('#' + jasmine.getFixtures().containerId).toContainElement('#checked-box')
Expand Down Expand Up @@ -578,11 +578,11 @@ describe("jQuery matcher", function () {
})

it("should pass for string properties with quote characters (double quotes)", function() {
var fontFace = '"Courier New", monospace';
var fontFace = '"Courier New", monospace';
$("#sandbox").css("font-family", fontFace);
expect($("#sandbox")).toHaveCss({'font-family': fontFace});
})

it("should pass for string properties with quote characters (single quotes)", function() {
var fontFace = "'Courier New', monospace";
$("#sandbox").css("font-family", fontFace);
Expand All @@ -594,7 +594,7 @@ describe("jQuery matcher", function () {
$("#sandbox").css("font-family", fontFace);
expect($("#sandbox")).toHaveCss({'font-family': fontFace});
});

it("should pass for string properties with no space", function() {
var fontFace = '"Courier New",monospace';
$("#sandbox").css("font-family", fontFace);
Expand Down Expand Up @@ -1470,6 +1470,12 @@ describe("jQuery matcher", function () {
expect($('#clickme').get(0)).not.toHandleWith("click.namespaced", aDifferentHandler)
})

it('should fail if there is no event bound at all', function () {
var handler = function (){}
expect($('#clickme')).not.toHandleWith('click', handler)
expect($('#clickme')).not.toHandleWith('click.namespaced', handler)
})

it('should pass if the namespaced event is not bound at all', function () {
expect($('#clickme')).not.toHandle("click.namespaced")
expect($('#clickme').get(0)).not.toHandle("click.namespaced")
Expand All @@ -1495,7 +1501,6 @@ describe("jQuery matcher", function () {
it('should not fail when actual is null', function (){
expect(null).not.toHandleWith('click')
})

})
})

Expand Down