Skip to content

Instantly share code, notes, and snippets.

@gauntface
Created March 6, 2017 22:12
Show Gist options
  • Select an option

  • Save gauntface/04e0c196fb5fc62fbfede3760b2247fb to your computer and use it in GitHub Desktop.

Select an option

Save gauntface/04e0c196fb5fc62fbfede3760b2247fb to your computer and use it in GitHub Desktop.
Testing a fake push event.
it('should be able to test a push event', function() {
const pushData = {
title: 'Example Title.',
body: 'Example Body.',
};
return new Promise((resolve, reject) => {
const fakePushEvent = new PushEvent('push', {
data: JSON.stringify(pushData),
});
// Override waitUntil so we can detect when the notification
// has been show by the push event.
fakePushEvent.waitUntil = (promise) => {
promise.then(resolve, reject);
};
self.dispatchEvent(fakePushEvent);
})
.then(() => {
// TODO: Test what the push event had done
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment