UNPKG

react-native-ui-lib

Version:

<p align="center"> <img src="https://user-images.githubusercontent.com/1780255/105469025-56759000-5ca0-11eb-993d-3568c1fd54f4.png" height="250px" style="display:block"/> </p> <p align="center">UI Toolset & Components Library for React Native</p> <p a

42 lines (33 loc) 1.5 kB
import _ from 'lodash'; import {ConnectionStatusBar} from '../index'; describe('ConnectionStatusBar', () => { let uut; beforeEach(() => { uut = new ConnectionStatusBar({}); ConnectionStatusBar.unregisterGlobalOnConnectionLost(); }); describe('registerGlobalOnConnectionLost', () => { it('should register a callback for when connection is lost', () => { const callback = jest.fn(); expect(ConnectionStatusBar.onConnectionLost).toBe(undefined); ConnectionStatusBar.registerGlobalOnConnectionLost(callback); expect(ConnectionStatusBar.onConnectionLost).toBe(callback); ConnectionStatusBar.unregisterGlobalOnConnectionLost(); expect(ConnectionStatusBar.onConnectionLost).toBe(undefined); }); it('should call onConnectionLost callback when connection state changed from connected to disconnected', () => { const callback = jest.fn(); ConnectionStatusBar.registerGlobalOnConnectionLost(callback); _.set(uut, 'state.isConnected', true); uut.onConnectionChange({type: 'none'}); expect(callback).toHaveBeenCalled(); }); it('should not call onConnectionLost callback when connection state changed from disconnected to connected', () => { const callback = jest.fn(); ConnectionStatusBar.registerGlobalOnConnectionLost(callback); _.set(uut, 'state.isConnected', false); uut.onConnectionChange({type: 'wifi'}); expect(callback).not.toHaveBeenCalled(); }); }); });