UNPKG

apphouse

Version:

Component library for React that uses observable state management and theme-able components.

47 lines (39 loc) 1.49 kB
import { NetworkStatusOptions, networkStatus } from './NetworkStatus'; describe('NetworkStatus', () => { beforeEach(() => { jest.clearAllMocks(); networkStatus.checkNetworkStatus = jest.fn(); }); test('it should set the initial status to "online"', () => { expect(networkStatus.status).toEqual(NetworkStatusOptions.online); }); // test('it should add event listeners for online and offline events', () => { // expect(window.addEventListener).toHaveBeenCalledTimes(2); // expect(window.addEventListener).toHaveBeenCalledWith( // 'online', // networkStatus.checkNetworkStatus, // false // ); // expect(window.addEventListener).toHaveBeenCalledWith( // 'offline', // networkStatus.checkNetworkStatus, // false // ); // }); // test('it should call checkNetworkStatus on initialization', () => { // expect(networkStatus.checkNetworkStatus).toHaveBeenCalled(); // }); // test('it should correctly update the status based on navigator.onLine', () => { // expect(networkStatus.currentNetworkStatus).toEqual( // NetworkStatusOptions.online // ); // Object.defineProperty(global.navigator, 'onLine', { // value: false, // configurable: true // }); // networkStatus.checkNetworkStatus(); // expect(networkStatus.currentNetworkStatus).toEqual( // NetworkStatusOptions.offline // ); // }); });