user2167582
user2167582

Reputation: 6388

how to test with custom dom event in angularjs

I have written custom events for mobile devices in jasmine, and I am trying to fire the events.

so instead of

angular.element()[0].click()

how may I trigger custom events and other events to trigger functions?

Upvotes: 2

Views: 1443

Answers (2)

jramoyo
jramoyo

Reputation: 336

To add to the above post, you can pass a custom event (with extra data) by doing this:

angular.element().triggerHandler({
 'type': 'my-custom-event-name',
 'foo':  'bar' 
});

Upvotes: 0

TheHippo
TheHippo

Reputation: 63179

This should work:

angular.element().triggerHandler('my-custom-event-name');

If you want to attach additional data to your event:

angular.element().triggerHandler('my-custom-event-name', {'foo': 'bar'});

Upvotes: 3

Related Questions