UNPKG

@brightlayer-ui/react-native-auth-workflow

Version:

Re-usable workflow components for Authentication and Registration within Eaton applications.

36 lines (35 loc) 2.1 kB
import React from 'react'; import '@testing-library/jest-dom'; import { cleanup, render, renderHook } from '@testing-library/react-native'; import { View } from 'react-native'; import { Text } from 'react-native-paper'; import { registrationContextProviderProps } from '../../testUtils'; import { RegistrationContextProvider, useRegistrationContext } from '../../contexts'; afterEach(cleanup); describe('RegistrationContextProvider', () => { it('should render RegistrationContextProvider without crashing', () => { const { getByText } = render(React.createElement(RegistrationContextProvider, Object.assign({}, registrationContextProviderProps), React.createElement(Text, null, "Hello Registration"))); expect(getByText('Hello Registration')).toBeTruthy(); }); it('should read values from the context', () => { const wrapper = ({ children }) => (React.createElement(RegistrationContextProvider, Object.assign({}, registrationContextProviderProps), children)); const { result } = renderHook(() => useRegistrationContext(), { wrapper }); expect(result.current.language).toBe('en'); }); it('should set values in the context', () => { const wrapper = ({ children }) => (React.createElement(RegistrationContextProvider, Object.assign({}, registrationContextProviderProps, { language: "es" }), children)); const { result } = renderHook(() => useRegistrationContext(), { wrapper }); expect(result.current.language).not.toBe('en'); expect(result.current.language).toBe('es'); }); it('should render multiple children', () => { const { getByText } = render(React.createElement(RegistrationContextProvider, Object.assign({}, registrationContextProviderProps), React.createElement(View, null, React.createElement(Text, null, "Child 1")), React.createElement(View, null, React.createElement(Text, null, "Child 2")))); expect(getByText('Child 1')).toBeTruthy(); expect(getByText('Child 2')).toBeTruthy(); }); });