import { ServiceWorkerService } from '@/services/service-worker.service'; const navigator: any = { serviceWorker: { getRegistration: vi.fn().mockReturnValue({ addEventListener: vi.fn(), installing: { addEventListener: vi.fn(), }, waiting: {}, update: vi.fn(), }), }, }; describe('ServiceWorkerService service tests', () => { it('should instantiate', () => { expect(ServiceWorkerService.Instantiate()).toBeTruthy(); }); it('should get registration', () => { vi.spyOn(globalThis, 'navigator', 'get').mockReturnValue(navigator); const registration = ServiceWorkerService.Instantiate().getRegistration(); expect(registration).toBeTruthy(); }); it('should not get registration', async () => { vi.spyOn(globalThis, 'navigator', 'get').mockReturnValue({} as any); const registration = await ServiceWorkerService.Instantiate().getRegistration(); expect(registration).toBeFalsy(); }); });