Skip to content

Instantly share code, notes, and snippets.

@zackargyle
Created March 27, 2017 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackargyle/2c59b9bc717678118349d4f952162254 to your computer and use it in GitHub Desktop.
Save zackargyle/2c59b9bc717678118349d4f952162254 to your computer and use it in GitHub Desktop.
const makeServiceWorkerEnv = require('service-worker-mock');
describe('Service worker', () => {
beforeEach(() => {
Object.assign(global, makeServiceWorkerEnv());
jest.resetModules();
});
it('should delete old caches on activate', async () => {
require('../sw.js');
// Create old cache
await self.caches.open('OLD_CACHE');
expect(self.snapshot().caches.OLD_CACHE).toBeDefined();
// Activate and verify old cache is removed
await self.trigger('activate');
expect(self.snapshot().caches.OLD_CACHE).toBeUndefined();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment