पाठ 25 / 29
PWAs को Test करना
Service workers, offline functionality और installation flow को test करें।
Testing Strategies
PWAs को test करें: offline behavior, service worker updates, caching correctness, real devices पर installation और accessibility। Chrome DevTools, Lighthouse और manual testing का उपयोग करें।
Service worker को unit test करें
Jest या Vitest के साथ service worker को test करें।
describe('Service Worker', () => {
it('should cache on install', async () => {
const cache = await caches.open('v1');
await cache.add('/index.html');
const cached = await cache.match('/index.html');
expect(cached).toBeDefined();
});
it('should serve from cache on fetch', async () => {
// Mock fetch event
const response = await cache.match('/index.html');
expect(response).toBeDefined();
});
});
Output:
Service worker caching and fetch behavior verified through tests.
एक आम गलती
हमेशा real devices पर real network conditions में test करें। Simulator throttling और localhost testing real-world issues को miss करते हैं।