import * as React from 'react'; import { cleanup, render } from '@testing-library/react'; import { Wrapper } from '.'; describe('Wrapper component', () => { afterEach(cleanup); test('Empty render', () => { const { container } = render(
); expect(container.innerHTML).toBe('
'); }); test('Render only children if wrapper are not specified', () => { const { container } = render(
Test string
); expect(container.innerHTML).toBe('
Test string
'); }); test('Render wrapper if true', () => { const wrapper: React.FC = ({ children }) => {children}; const { container } = render(
Test string
); expect(container.innerHTML).toBe('
Test string
'); }); test('Use wrap function if true', () => { const wrap = (children: React.ReactNode) => {children}; const { container } = render(
Test string
); expect(container.innerHTML).toBe('
Test string
'); }); test('Don\'t render wrapper if false', () => { const wrapper: React.FC = ({ children }) => {children}; const { container } = render(
Test string
); expect(container.innerHTML).toBe('
Test string
'); }); test('Don\'t use wrap function if false', () => { const wrap = (children: React.ReactNode) => {children}; const { container } = render(
Test string
); expect(container.innerHTML).toBe('
Test string
'); }); test('Accept function as child', () => { const wrap = (children: React.ReactNode) => {children}; const child = () => <>Test string; const { container } = render(
{child}
); expect(container.innerHTML).toBe('
Test string
'); }); test('Wrap can return undefined', () => { const wrap = () => undefined as any; const child = 'Test string'; const { container } = render(
{child}
); expect(container.innerHTML).toBe('
'); }); });