Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

feat(jqLite): support isDefaultPrevented for triggerHandler dummies #8008

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 6 additions & 1 deletion src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,12 @@ forEach({
eventData = eventData || [];

var event = [{
preventDefault: noop,
preventDefault: function() {
this.defaultPrevented = true;
},
isDefaultPrevented: function() {
return this.defaultPrevented === true;
},
stopPropagation: noop
}];

Expand Down
14 changes: 14 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,20 @@ describe('jqLite', function() {
data = pokeSpy.mostRecentCall.args[1];
expect(data.hello).toBe("world");
});

it('should mark event as prevented if preventDefault is called', function() {
var element = jqLite('<a>poke</a>'),
pokeSpy = jasmine.createSpy('poke'),
event;

element.on('click', pokeSpy);
element.triggerHandler('click');
event = pokeSpy.mostRecentCall.args[0];

expect(event.isDefaultPrevented()).toBe(false);
event.preventDefault();
expect(event.isDefaultPrevented()).toBe(true);
});
});


Expand Down