jeudi 21 juillet 2016

How to remove a window / navigator JS API for unit testing?

I'd like to test the behaviour of a library when an API doesn't exist in a browser.

For example if I have the following check:

if ('serviceWorker' in navigator &&
'PushManager' in window &&
'Notification' in window &&
'showNotification' in ServiceWorkerRegistration.prototype) {
   // Do something
} else {
   throw new Error('Catch in test');
}

Is it possible to completely remove properties on these global scopes?

Aucun commentaire:

Enregistrer un commentaire