@brightlayer-ui/react-native-auth-workflow
Version:
Re-usable workflow components for Authentication and Registration within Eaton applications.
34 lines (33 loc) • 1.88 kB
JavaScript
import React from 'react';
import { Text } from 'react-native-paper';
import '@testing-library/jest-dom';
import { render, cleanup, screen, renderHook } from '@testing-library/react-native';
import { AuthContextProvider } from '../../contexts/AuthContext/provider';
import { useAuthContext } from '../../contexts/AuthContext';
import { authContextProviderProps } from '../../testUtils';
afterEach(cleanup);
describe('AuthContextProvider', () => {
it('should render AuthContextProvider without crashing', () => {
render(React.createElement(AuthContextProvider, Object.assign({}, authContextProviderProps),
React.createElement(Text, null, "Hello Auth")));
expect(screen.getByText('Hello Auth')).toBeTruthy();
});
it('should read values from the context', () => {
const wrapper = ({ children }) => (React.createElement(AuthContextProvider, Object.assign({}, authContextProviderProps), children));
const { result } = renderHook(() => useAuthContext(), { wrapper });
expect(result.current.language).toBe('en');
});
it('should set values in the context', () => {
const wrapper = ({ children }) => (React.createElement(AuthContextProvider, Object.assign({}, authContextProviderProps, { language: "es" }), children));
const { result } = renderHook(() => useAuthContext(), { wrapper });
expect(result.current.language).not.toBe('en');
expect(result.current.language).toBe('es');
});
it('should render multiple children', () => {
render(React.createElement(AuthContextProvider, Object.assign({}, authContextProviderProps),
React.createElement(Text, null, "Child 1"),
React.createElement(Text, null, "Child 2")));
expect(screen.getByText('Child 1')).toBeTruthy();
expect(screen.getByText('Child 2')).toBeTruthy();
});
});