Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const makeServiceWorkerEnv = require('service-worker-mock');
- const Response = () => ({ clone: jest.fn() });
- const Request = () => ({ url: '/test' });
- describe('Service worker', () => {
- beforeEach(() => {
- Object.assign(global, makeServiceWorkerEnv());
- jest.resetModules();
- });
- it('should return a cached response', async () => {
- global.fetch = jest.fn(() => Response());
- require('../sw.js');
- // Cache a request
- const cachedResponse = Response();
- const cache = await self.caches.open('TEST');
- cache.put(Request(), cachedResponse);
- // Verify the response is the cachedResponse
- const response = await self.trigger('fetch', Request());
- expect(response).toBe(cachedResponse);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement