Created
March 27, 2017 00:49
-
-
Save zackargyle/eaa93a9fc01e9ba510c999dcfdcf9ab4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment