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

Commit 7e71acd

Browse files
shahataIgorMinar
authored andcommitted
feat(jqLite): support isDefaultPrevented for triggerHandler dummies
triggerHandler sends dummy events to an element, but although the event includes the preventDefault method, there is no way to see if it was called for the event. This is sometimes important when testing directives that use preventDefault Closes #8008
1 parent 0235420 commit 7e71acd

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/jqLite.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,12 @@ forEach({
953953
eventData = eventData || [];
954954

955955
var event = [{
956-
preventDefault: noop,
956+
preventDefault: function() {
957+
this.defaultPrevented = true;
958+
},
959+
isDefaultPrevented: function() {
960+
return this.defaultPrevented === true;
961+
},
957962
stopPropagation: noop
958963
}];
959964

test/jqLiteSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,20 @@ describe('jqLite', function() {
16901690
data = pokeSpy.mostRecentCall.args[1];
16911691
expect(data.hello).toBe("world");
16921692
});
1693+
1694+
it('should mark event as prevented if preventDefault is called', function() {
1695+
var element = jqLite('<a>poke</a>'),
1696+
pokeSpy = jasmine.createSpy('poke'),
1697+
event;
1698+
1699+
element.on('click', pokeSpy);
1700+
element.triggerHandler('click');
1701+
event = pokeSpy.mostRecentCall.args[0];
1702+
1703+
expect(event.isDefaultPrevented()).toBe(false);
1704+
event.preventDefault();
1705+
expect(event.isDefaultPrevented()).toBe(true);
1706+
});
16931707
});
16941708

16951709

0 commit comments

Comments
 (0)