I'm trying to test my webapp where I show a js Notification:
new Notification("Title")
. Then I need to test if certain behaviour happens when I click on it. How can I simulate a user click on the notification in javascript?
Asked
Active
Viewed 144 times
0

Veselin
- 197
- 2
- 12
-
1Possible duplicate of [How to trigger event in JavaScript?](http://stackoverflow.com/questions/2490825/how-to-trigger-event-in-javascript) – Robba Jan 06 '17 at 08:20
1 Answers
0
Store notification object you get after the construction.Then you can do anything
var notification = new Notification('test', {
icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
body: 'this is body of the notification'
});
notification.onclick = function() { alert('got clicked'); } //handler
var event = new Event('click'); //event creation
notification.dispatchEvent(event); //triggering

Vinay
- 7,442
- 6
- 25
- 48