Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. const makeServiceWorkerEnv = require('service-worker-mock');
  2. const Response = () => ({ clone: jest.fn() });
  3. const Request = () => ({ url: '/test' });
  4.  
  5. describe('Service worker', () => {
  6. beforeEach(() => {
  7. Object.assign(global, makeServiceWorkerEnv());
  8. jest.resetModules();
  9. });
  10.  
  11. it('should return a cached response', async () => {
  12. global.fetch = jest.fn(() => Response());
  13. require('../sw.js');
  14.  
  15. // Cache a request
  16. const cachedResponse = Response();
  17. const cache = await self.caches.open('TEST');
  18. cache.put(Request(), cachedResponse);
  19.  
  20. // Verify the response is the cachedResponse
  21. const response = await self.trigger('fetch', Request());
  22. expect(response).toBe(cachedResponse);
  23. });
  24. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement