UNPKG

@yoroi/common

Version:
54 lines (53 loc) 1.99 kB
"use strict"; import { render, screen } from '@testing-library/react-native'; import * as React from 'react'; import { Text, View } from 'react-native'; import { mountAsyncStorage } from '../adapters/async-storage'; import { AsyncStorageProvider, useAsyncStorage } from './async-storage-reactjs'; import { jsx as _jsx } from "react/jsx-runtime"; const rootStorage = mountAsyncStorage({ path: '/' }); describe('AsyncStorageProvider and useAsyncStorage Tests', () => { test('AsyncStorageProvider provides storage context', () => { const TestComponent = () => { const storage = useAsyncStorage(); return /*#__PURE__*/_jsx(View, { children: /*#__PURE__*/_jsx(Text, { children: storage ? 'Storage Available' : 'Storage Unavailable' }) }); }; render(/*#__PURE__*/_jsx(AsyncStorageProvider, { storage: rootStorage, children: /*#__PURE__*/_jsx(TestComponent, {}) })); expect(screen.getByText('Storage Available')).toBeTruthy(); }); test('AsyncStorageProvider provides the default rootStorage context', () => { const TestComponent = () => { const storage = useAsyncStorage(); return /*#__PURE__*/_jsx(View, { children: /*#__PURE__*/_jsx(Text, { children: storage ? 'Storage Available' : 'Storage Unavailable' }) }); }; render(/*#__PURE__*/_jsx(AsyncStorageProvider, { children: /*#__PURE__*/_jsx(TestComponent, {}) })); expect(screen.getByText('Storage Available')).toBeTruthy(); }); test('useAsyncStorage throws error without AsyncStorageProvider', () => { const InvalidComponent = () => { useAsyncStorage(); return /*#__PURE__*/_jsx(View, { children: /*#__PURE__*/_jsx(Text, { children: "Invalid Component" }) }); }; expect(() => render(/*#__PURE__*/_jsx(InvalidComponent, {}))).toThrow('Missing AsyncStorageProvider'); }); }); //# sourceMappingURL=async-storage-reactjs.test.js.map