I test redux-actions with jest. Particular redux-action uses Notifications API as a side-effect. How can i mock Notifications API?
Now, i simply mock it this way:
global.Notification = {...};
It works, but i think there is more elegant solution to solve this problem. Any ideas?
I have this module to handle Notifications API:
export const requestNotifyPermission = () => {
try {
return Notification.requestPermission().then(function(result) {
return result;
});
} catch(err) {
console.warn('NotificationsAPI error: ' + err);
}
};
export const getCurrentNotifyPermission = () => {
// Possible values = default, granted, denied
try {
return Notification.permission;
} catch {
return 'denied';
}
};
export const createNotify = (title, body) => {
try {
if (getCurrentNotifyPermission() === 'granted') {
var options = {
body: body
};
return new Notification(title, options);
}
} catch(err) {
console.warn('NotificationsAPI error: ' + err);
}
}