Files
kochwas/tests/unit/network-store.test.ts
hsiegeln 04641355df
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m31s
feat(pwa): Online-Status-Store
Reaktiver Store basierend auf navigator.onLine und den window-
Events online/offline. Kein aktives Heuristik-Probing — für
unseren Offline-PWA-Use-Case reicht der Browser-Status. Wird von
SyncIndicator und require-online-Helper konsumiert.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 16:17:11 +02:00

24 lines
846 B
TypeScript

// @vitest-environment jsdom
import { describe, it, expect, beforeEach } from 'vitest';
describe('network store', () => {
beforeEach(() => {
// Reset module state for each test
Object.defineProperty(navigator, 'onLine', { value: true, configurable: true });
});
it('reflects initial navigator.onLine and reacts to events', async () => {
const { network } = await import('../../src/lib/client/network.svelte');
network.init();
expect(network.online).toBe(true);
Object.defineProperty(navigator, 'onLine', { value: false, configurable: true });
window.dispatchEvent(new Event('offline'));
expect(network.online).toBe(false);
Object.defineProperty(navigator, 'onLine', { value: true, configurable: true });
window.dispatchEvent(new Event('online'));
expect(network.online).toBe(true);
});
});