import React from 'react' import { render, screen } from '@testing-library/react' import { IntlProvider } from 'react-intl' import { vi } from 'vitest' import { OptionalIntlProvider } from '.' vi.mock('@cultureamp/i18n-react-intl', () => ({ StaticIntlProvider: ({ children }: { children: React.ReactElement }) => (
{children}
), })) describe('', () => { it('wraps the children in a StaticIntlProvider when no other react-intl provider is present', async () => { render(
children
, ) const result = await screen.findByTestId('mockedIntlProvider') expect(result).toBeInTheDocument() const childrenResult = await screen.findByText('children') expect(childrenResult).toBeInTheDocument() }) it('does not wrap the children in a StaticIntlProvider when a react-intl provider is present', async () => { render(
children
, ) const result = screen.queryByTestId('mockedIntlProvider') expect(result).not.toBeInTheDocument() const childrenResult = await screen.findByText('children') expect(childrenResult).toBeInTheDocument() }) })